コード例 #1
0
 public function uploadCategoryImage($file, $image_ext, $image_name, $destinationpath, $reference_id, $mode)
 {
     $return_arr = array();
     $config_path = \Config::get('webshoppack::product_category_image_folder');
     CUtil::chkAndCreateFolder($config_path);
     // open file a image resource
     \Image::make($file->getRealPath())->save(\Config::get("webshoppack::product_category_image_folder") . $image_name . '_O.' . $image_ext);
     list($width, $height) = getimagesize($file);
     list($upload_img['width'], $upload_img['height']) = getimagesize(base_path() . '/public/' . $config_path . $image_name . '_O.' . $image_ext);
     $thumb_width = \Config::get("webshoppack::product_category_image_thumb_width");
     $thumb_height = \Config::get("webshoppack::product_category_image_thumb_height");
     if (isset($thumb_width) && isset($thumb_height)) {
         $timg_size = CUtil::DISP_IMAGE($thumb_width, $thumb_height, $upload_img['width'], $upload_img['height'], true);
         \Image::make($file->getRealPath())->resize($thumb_width, $thumb_height, true, false)->save($config_path . $image_name . '_T.' . $image_ext);
     }
     $img_path = base_path() . '/public/' . $config_path;
     list($upload_input['thumb_width'], $upload_input['thumb_height']) = getimagesize($img_path . $image_name . '_T.' . $image_ext);
     if ($mode == 'edit') {
         $this->deleteExistingImageFiles($reference_id);
     }
     $return_arr = array('image_ext' => $image_ext, 'image_name' => $image_name, 'image_width' => $upload_input['thumb_width'], 'image_height' => $upload_input['thumb_height']);
     return $return_arr;
 }
コード例 #2
0
 public function uploadMediaFile($file_ctrl_name, $file_type, &$file_info, $download_file = false)
 {
     if (!isset($_FILES[$file_ctrl_name])) {
         return array('status' => 'error', 'error_message' => trans("webshoppack::product.products_select_file"));
     }
     // default settings
     $file_original = '';
     $file_thumb = '';
     $file_large = '';
     $width = 0;
     $height = 0;
     $t_width = 0;
     $t_height = 0;
     $l_width = 0;
     $l_height = 0;
     $server_url = '';
     $is_downloadable = 'No';
     $file = \Input::file('uploadfile');
     $file_size = $file->getClientSize();
     if ($file_size == 0) {
         return array('status' => 'error', 'error_message' => trans("webshoppack::product.common_err_tip_invalid_file_size"));
     }
     $upload_file_name = $file->getClientOriginalName();
     $ext_index = strrpos($upload_file_name, '.') + 1;
     $ext = substr($upload_file_name, $ext_index, strlen($upload_file_name));
     $title = substr($upload_file_name, 0, $ext_index - 1);
     $filename_no_ext = uniqid();
     // generate filename
     //$file = $filename_no_ext . '.' . $ext;
     if (!($file_size <= $this->product_max_upload_size * 1024 * 1024)) {
         return array('status' => 'error', 'error_message' => trans("webshoppack::product.common_err_tip_invalid_file_size"));
     }
     switch ($file_type) {
         case 'image':
             $file_path = \Config::get("webshoppack::photos_folder");
             $server_url = \URL::asset($file_path);
             $file_original = $filename_no_ext . '.' . $ext;
             $file_thumb = $filename_no_ext . 'T.' . $ext;
             $file_large = $filename_no_ext . 'L.' . $ext;
             $file_indexsmall = $filename_no_ext . 'IS.' . $ext;
             CUtil::chkAndCreateFolder($file_path);
             @chmod($file_original, 0777);
             @chmod($file_thumb, 0777);
             @chmod($file_large, 0777);
             @chmod($file_indexsmall, 0777);
             try {
                 \Image::make($file->getRealPath())->save($file_path . $file_original);
                 //Resize original image for large image
                 \Image::make($file->getRealPath())->resize(\Config::get("webshoppack::photos_large_width"), \Config::get("webshoppack::photos_large_height"), true, false)->save($file_path . $file_large);
                 //Resize original image for thump image
                 \Image::make($file->getRealPath())->resize(\Config::get("webshoppack::photos_thumb_width"), \Config::get("webshoppack::photos_thumb_height"), true, false)->save($file_path . $file_thumb);
                 //Resize original image for small image for index page
                 \Image::make($file->getRealPath())->resize(\Config::get("webshoppack::photos_indexsmall_width"), \Config::get("webshoppack::photos_indexsmall_height"), false, false)->save($file_path . $file_indexsmall);
             } catch (\Exception $e) {
                 return array('status' => 'error', 'error_message' => $e->getMessage());
             }
             list($width, $height) = getimagesize($file_path . $file_original);
             list($l_width, $l_height) = getimagesize($file_path . $file_large);
             list($t_width, $t_height) = getimagesize($file_path . $file_thumb);
             break;
         default:
             $file_type = $file_type == 'archive' ? 'zip' : $file_type;
             $file_path = \Config::get("webshoppack::archive_folder");
             try {
                 $file->move($file_path, $file_path . $filename_no_ext . '.' . $ext);
             } catch (\Exception $e) {
                 return array('status' => 'error', 'error_message' => trans("webshoppack::product.products_file_upload_error"));
             }
             $is_downloadable = $download_file ? 'Yes' : 'No';
             break;
     }
     $file_info = array('title' => $title, 'filename_no_ext' => $filename_no_ext, 'ext' => $ext, 'file_original' => $file_original, 'file_thumb' => $file_thumb, 'file_large' => $file_large, 'width' => $width, 'height' => $height, 't_width' => $t_width, 't_height' => $t_height, 'l_width' => $l_width, 'l_height' => $l_height, 'server_url' => $server_url, 'is_downloadable' => $is_downloadable);
     return array('status' => 'success');
 }