Пример #1
0
 public function process()
 {
     $oimages = new OnpubImages($this->pdo);
     $owebsites = new OnpubWebsites($this->pdo);
     if ($this->overwrite !== NULL) {
         // An image overwrite is being requested.
         $image = new OnpubImage();
         $image->websiteID = $this->websiteID;
         $image->fileName = $this->overwriteFileName;
         try {
             $this->imageID = $oimages->getID($image);
         } catch (PDOException $e) {
             throw $e;
         }
         try {
             $website = $owebsites->get($this->websiteID);
         } catch (PDOException $e) {
             throw $e;
         }
         if ($this->overwrite) {
             // Overwrite the existing image file with the temp one.
             if (rename(addTrailingSlash($website->imagesDirectory) . $this->overwriteFileName . ONPUBGUI_TMP_IMG_SUFFIX, addTrailingSlash($website->imagesDirectory) . $this->overwriteFileName)) {
                 // Update the image's modified timestamp in the DB.
                 try {
                     $image = $oimages->get($this->imageID);
                 } catch (PDOException $e) {
                     throw $e;
                 }
                 try {
                     $oimages->update($image);
                 } catch (PDOException $e) {
                     throw $e;
                 }
             }
         } else {
             // Remove the temporary image file.
             unlink(addTrailingSlash($website->imagesDirectory) . $this->overwriteFileName . ONPUBGUI_TMP_IMG_SUFFIX);
         }
         return;
     }
     if (!ini_get("file_uploads")) {
         $message = "File uploads are disabled in the current PHP configuration.";
         throw new Exception($message, ONPUBGUI_ERROR_IMAGE_TYPE);
     }
     for ($i = 0; $i < sizeof($this->imageFiles['name']); $i++) {
         if ($this->imageFiles['name'][$i]) {
             if (!$this->isValidImage($this->imageFiles['name'][$i])) {
                 $message = "<i>" . $this->imageFiles['name'][$i] . "</i> is an unsupported image file type.";
                 throw new Exception($message, ONPUBGUI_ERROR_IMAGE_TYPE);
             }
             $image = new OnpubImage();
             $image->websiteID = $this->websiteID;
             $image->fileName = $this->imageFiles['name'][$i];
             try {
                 $this->imageID = $oimages->getID($image);
             } catch (PDOException $e) {
                 throw $e;
             }
             try {
                 $website = $owebsites->get($image->websiteID);
             } catch (PDOException $e) {
                 throw $e;
             }
             if ($this->imageID) {
                 // Image exists, write the file to the images directory with a temp
                 // name, and prompt the user to overwrite existing file.
                 if (is_uploaded_file($this->imageFiles['tmp_name'][$i])) {
                     if (@move_uploaded_file($this->imageFiles['tmp_name'][$i], addTrailingSlash($website->imagesDirectory) . $this->imageFiles['name'][$i] . ONPUBGUI_TMP_IMG_SUFFIX)) {
                         throw new Exception($this->imageFiles['name'][$i], ONPUBGUI_ERROR_IMAGE_EXISTS);
                     } else {
                         $imagesDirectory = $website->imagesDirectory;
                         $message = "Unable to move <i>" . $this->imageFiles['tmp_name'][$i] . "</i> to <i>" . addTrailingSlash($imagesDirectory) . $this->imageFiles['name'][$i] . ONPUBGUI_TMP_IMG_SUFFIX . "</i>.";
                         throw new Exception($message, ONPUBGUI_ERROR_MOVE_UPLOADED_FILE);
                     }
                 }
             } else {
                 // Image does not exsist, copy to images folder and insert in to DB.
                 if (is_uploaded_file($this->imageFiles['tmp_name'][$i])) {
                     if (!@move_uploaded_file($this->imageFiles['tmp_name'][$i], addTrailingSlash($website->imagesDirectory) . $this->imageFiles['name'][$i])) {
                         $imagesDirectory = $website->imagesDirectory;
                         $message = "Unable to move <i>" . $this->imageFiles['tmp_name'][$i] . "</i> to <i>" . addTrailingSlash($imagesDirectory) . $this->imageFiles['name'][$i] . "</i>.";
                         throw new Exception($message, ONPUBGUI_ERROR_MOVE_UPLOADED_FILE);
                     }
                     try {
                         $this->imageID = $oimages->insert($image);
                     } catch (PDOException $e) {
                         throw $e;
                     }
                 } else {
                     $imagesDirectory = $website->imagesDirectory;
                     $message = "<i>" . $this->imageFiles['name'][$i] . "</i> file size is larger than the current PHP configuration allows.";
                     throw new Exception($message, ONPUBGUI_ERROR_FILE_SIZE);
                 }
             }
         }
     }
 }
Пример #2
0
 public function process()
 {
     $oimages = new OnpubImages($this->pdo);
     $owebsites = new OnpubWebsites($this->pdo);
     $image = $oimages->get($this->oimage->ID);
     $website = $owebsites->get($image->websiteID);
     if ($this->oimage->fileName != $this->oldImageFileName) {
         if (file_exists(addTrailingSlash($website->imagesDirectory) . $this->oldImageFileName)) {
             rename(addTrailingSlash($website->imagesDirectory) . $this->oldImageFileName, addTrailingSlash($website->imagesDirectory) . $this->oimage->fileName);
         }
     }
     try {
         $oimages->update($this->oimage);
     } catch (PDOException $e) {
         throw $e;
     }
 }