1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| class Fichier {
public $nom;
public $repertoire;
public function __construct($nom, $repertoire) {
$this->nom = $nom;
$this->repertoire = $repertoire;
}
public function creerAdresse() {
if (!isset($this->adresse)) {
$this->adresse = 'http://' . $_SERVER['SERVER_NAME'] . '/' . $this->repertoire . '/' . $this->nom;
}
return $this->adresse;
}
public function creerChemin() {
if (!isset($this->chemin)) {
$this->chemin = $_SERVER['DOCUMENT_ROOT'] . '/' . $this->repertoire . '/' . $this->nom;
}
return $this->chemin;
}
public function creerExtension() {
if (!isset($this->extension)) {
$this->extension = self::obtenirExtension($this->nom);
}
return $this->extension;
}
public function renommer($nouveauNom) {
rename($this->creerChemin(), str_replace($this->nom, $nouveauNom, $this->creerChemin()));
$this = new Fichier($this->repertoire, $nouveauNom);
}
public function supprimer() {
unlink($this->creerChemin());
unset($this);
}
public static function obtenirExtension($nom) {
preg_match('/.+\.(.+)$/', $nom, $resultats);
return $resultats[1];
}
public static function verifierNom($nom) {
if (preg_match('/.+\..+$/', $nom)) {
return true;
} else {
return false;
}
}
} |
Partager