page = $page; $this->time = time(); $this->makeFileList(); } // tableaux des noms des fichiers public function makeFileList() { $this->fileList = glob('data/' . $this->page . '/' . $this->format . '/*.' . $this->format); //$this->files = glob('*.' . $this->format); } /*public function makeFilePath() {}*/ // nom d'un fichier public function findFileName($numArticle) { if($numArticle > 0) { $this->fileName = $this->fileList[$numArticle - 1]; } } public function setFileName() { if(file_exists('data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.' . $this->format)) { $this->fileName = 'data/' . $this->page . '/' . $this->format . '/' . $this->albumCode . '.' . $this->format; } } // GET // SET // fonctions CRUD (create - read - update - delete) // create public function create($content) { //$format = 'html'; // nommer les fichiers avec le timestamp pour: // - les trier par ordre chronologique // - rendre quasi impossible d'avoir deux fois le même nom (à la condition de gérer la "concurrence") $nom_fichier = 'data/' . $this->page . '/' . $format . '/' . $this->time . '.' . $format; $fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser fputs($fichier, $content); fclose($fichier); chmod($nom_fichier, 0666); } // read public function readAll() { $i = 0; $articles = []; foreach ($this->fileList as $oneFile) { $articles[$i] = file_get_contents($oneFile); $i++; } //print_r($articles); return $articles; } public function readOne() { return(file_get_contents($this->fileName)); } // update public function update($content) { $file = fopen($this->fileName, 'w'); // crée ou écrase fputs($file, $content); fclose($file); //chown($this->fileName, 'http'); chmod($this->fileName, 0666); } // delete public function delete() { unlink($this->fileName); } }