Esempio n. 1
0
 /**
  * Establishes dimensions for the image, then sends for processing
  *
  * @param array $file
  * @return string    Image path on success or FALSE on failure
  */
 public function check_image($file, $dir = NULL, $rename = TRUE)
 {
     $img_ctrl = new ImageControl();
     if (isset($dir) && strlen($dir) > 0) {
         $img_ctrl->dir = $dir;
         $img_ctrl->checkDir();
     }
     // If no errors occurred in the upload, process the image
     if ($file['error'] == 0) {
         // Make sure it's processed as the right type of image
         if ($file['type'] !== IMG_JPG || $file['type'] !== IMG_GIF || $file['type'] !== IMG_PNG) {
             $extension = array_shift(array_reverse(explode('.', $file['name'])));
             if ($extension === 'jpg') {
                 $file['type'] = IMG_JPG;
             } else {
                 if ($extension === 'gif') {
                     $file['type'] = IMG_GIF;
                 } else {
                     if ($extension === 'png') {
                         $file['type'] = IMG_PNG;
                     } else {
                         ECMS_Error::log_exception(new Exception("Unrecognized file type"));
                     }
                 }
             }
         }
         $img_ctrl->max_dims = array(IMG_MAX_WIDTH, IMG_MAX_HEIGHT);
         try {
             // Store the image
             $stored = $img_ctrl->processUploadedImage($file, $rename);
             if (!$stored) {
                 return FALSE;
             } else {
                 // Create a preview of the image
                 $img_ctrl->preview = TRUE;
                 $img_ctrl->max_dims = array(IMG_PREV_WIDTH, IMG_PREV_HEIGHT);
                 if (!$img_ctrl->processStoredImage($stored)) {
                     throw new Exception("Couldn't create image preview!");
                 }
                 // Create a square thumbnail of the image
                 $img_ctrl->preview = FALSE;
                 $img_ctrl->max_dims = array(IMG_THUMB_SIZE, IMG_THUMB_SIZE);
                 if ($img_ctrl->processStoredImage($stored, TRUE)) {
                     return substr($stored, 0, 1) === '/' ? $stored : '/' . $stored;
                 } else {
                     return FALSE;
                 }
             }
         } catch (Exception $e) {
             ECMS_Error::log_exception($e);
         }
     } else {
         return FALSE;
     }
 }