Ejemplo n.º 1
0
 /**
  * This function handles the file upload
  * and image resizing when necessary
  *
  * @param array $d
  * @return boolean
  */
 function handleFileUpload(&$d)
 {
     global $vmLogger, $VM_LANG, $mosConfig_absolute_path;
     require_once CLASSPATH . 'imageTools.class.php';
     // Uploaded file branch
     $upload_success = false;
     $fileinfo = pathinfo($_FILES['file_upload']['name']);
     $d['ext'] = $ext = $fileinfo["extension"];
     if ($this->fileexists) {
         // must rename uploaded file!
         $d['filename'] = uniqid(substr(basename($_FILES['file_upload']['name']), 0, 20)) . ".{$ext}";
     } else {
         $d['filename'] = $_FILES['file_upload']['name'];
     }
     // This plays a role when a file is added from the ps_product class
     // on adding and updating a downloadable product
     if ($d['file_type'] == 'downloadable_file') {
         $d["file_title"] = $d['filename'];
     }
     switch ($d["upload_dir"]) {
         case "IMAGEPATH":
             $uploaddir = IMAGEPATH . "product/";
             break;
         case "FILEPATH":
             $uploaddir = $mosConfig_absolute_path . trim($d["file_path"]);
             if (!file_exists($uploaddir)) {
                 @mkdir($uploaddir);
             }
             if (!file_exists($uploaddir)) {
                 $vmLogger->err($VM_LANG->_('PHPSHOP_FILES_PATH_ERROR', false));
                 return false;
             }
             if (substr($uploaddir, strlen($uploaddir) - 1, 1) != '/') {
                 $uploaddir .= '/';
             }
             break;
         case "DOWNLOADPATH":
             $uploaddir = DOWNLOADROOT;
             break;
     }
     $d['uploaddir'] = $uploaddir;
     if ($this->checkUploadedFile('file_upload')) {
         $d['upload_success'] = $this->moveUploadedFile('file_upload', $uploaddir . $d['filename']);
     } else {
         $vmLogger->err($VM_LANG->_('PHPSHOP_FILES_UPLOAD_FAILURE', false));
         return false;
     }
     switch (@$d['file_type']) {
         case 'image':
         case 'product_images':
         case 'product_full_image':
         case 'product_thumb_image':
             $d['is_image'] = "1";
             $d["file_url"] = IMAGEURL . "product/" . $d['filename'];
             if (!empty($d["file_create_thumbnail"])) {
                 $tmp_filename = $uploaddir . $d['filename'];
                 ## RESIZE THE IMAGE ####
                 $height = intval($d['thumbimage_height']);
                 $width = intval($d['thumbimage_width']);
                 $d['fileout'] = $fileout = $this->createThumbImage($tmp_filename, 'product', $height, $width);
                 if (is_file($fileout)) {
                     $vmLogger->info($VM_LANG->_('PHPSHOP_FILES_IMAGE_RESIZE_SUCCESS', false));
                     $thumbimg = getimagesize($fileout);
                     $d['file_image_thumb_width'] = $thumbimg[0];
                     $d['file_image_thumb_height'] = $thumbimg[1];
                     //a25
                     $ss_str_wh_in = '_' . $height . 'x' . $width . '.';
                     $ss_str_wh_out = '_' . $d['file_image_thumb_height'] . 'x' . $d['file_image_thumb_width'] . '.';
                     $ss_new_fileout = str_replace($ss_str_wh_in, $ss_str_wh_out, $fileout);
                     rename($fileout, $ss_new_fileout);
                     $d['fileout'] = str_replace($ss_str_wh_in, $ss_str_wh_out, $d['fileout']);
                     //						echo $ss_str_wh_in.'|-|'.$ss_str_wh_out.'|-|'.$fileout.'|-|'.$ss_new_fileout;
                     ///a25
                 } else {
                     $vmLogger->warning($VM_LANG->_('PHPSHOP_FILES_IMAGE_RESIZE_FAILURE', false));
                     $d['file_image_thumb_height'] = "";
                     $d['file_image_thumb_width'] = "";
                 }
                 $fullimg = getimagesize($tmp_filename);
                 $d['file_image_width'] = $fullimg[0];
                 $d['file_image_height'] = $fullimg[1];
             }
             if (!empty($d["file_resize_fullimage"])) {
                 // Resize the full image!
                 $height = intval($d['fullimage_height']);
                 $width = intval($d['fullimage_width']);
                 vmImageTools::resizeImage($uploaddir . $d['filename'], $uploaddir . $d['filename'], $width, $height);
                 $fullimg = getimagesize($uploaddir . $d['filename']);
                 $d['file_image_width'] = $fullimg[0];
                 $d['file_image_height'] = $fullimg[1];
             }
             break;
         default:
             ### File Upload ###
             $d['is_image'] = "0";
             $d['file_image_height'] = $d['file_image_width'] = $d['file_image_thumb_height'] = $d['file_image_thumb_width'] = "";
             break;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Resizes an image
  *
  * @param string $fileName
  * @param string $section
  * @param int $height
  * @param int $width
  * @return string
  */
 function createThumbImage($fileName, $section = 'product', $height = PSHOP_IMG_HEIGHT, $width = PSHOP_IMG_WIDTH)
 {
     require_once CLASSPATH . 'imageTools.class.php';
     /* Generate Image Destination File Name */
     $pathinfo = pathinfo($fileName);
     $to_file_thumb = basename($fileName, '.' . $pathinfo['extension']) . "_" . $height . "x" . $width . "." . $pathinfo['extension'];
     $fileout = IMAGEPATH . "{$section}/resized/" . $to_file_thumb;
     vmImageTools::resizeImage($fileName, $fileout, $height, $width);
     return $fileout;
 }