Exemplo n.º 1
0
 /**
  * Méthode d'envoi de déclenchement des actions d'uploads, redimensionnement...
  * @throws Exception
  * @param bool $pCreateFolder
  * @return bool
  */
 public function send($pCreateFolder = false)
 {
     if ($pCreateFolder && !is_dir($this->folder)) {
         Folder::create($this->folder);
     }
     if (!isset($this->fileData) || $this->fileData["error"] != 0) {
         throw new Exception("Upload impossible : une erreur est survenue");
     }
     if (!@is_uploaded_file($this->fileData["tmp_name"])) {
         throw new Exception("Upload impossible");
     }
     if (!@move_uploaded_file($this->fileData["tmp_name"], $this->pathFile)) {
         throw new Exception("Upload impossible : le dossier cible n'existe pas");
     }
     chmod($this->pathFile, 0666);
     if (is_array($this->newSize) && count($this->newSize) == 2) {
         if (!Image::resize($this->pathFile, $this->newSize[0], $this->newSize[1])) {
             throw new Exception("Upload effectué : redimensionnement impossible");
         }
     }
     if ($this->miniatures) {
         $max = count($this->miniatures);
         for ($i = 0; $i < $max; ++$i) {
             Image::createCopy($this->pathFile, $this->miniatures[$i]["pathFile"], $this->miniatures[$i]["width"], $this->miniatures[$i]["height"]);
         }
     }
     if (!$this->model_upload->insertUpload($this->pathFile)) {
         $this->cancelUpload();
         throw new Exception("Upload impossible : erreur lors de l'insertion dans la base.");
     }
     $this->isUpload = true;
     $this->id_upload = $this->model_upload->getInsertId();
     return $this->isUpload;
 }