Example #1
0
 public function changeSlide($fileName)
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             $imageHandler->cropAndScaleFromCenter(1040, 380);
             $imageHandler->save($this->getSliderImagePath($fileName));
             $this->response = array('fileName' => $fileName, 'imageSrc' => $this->getSliderImageSrc($fileName));
             return TRUE;
         } catch (CException $e) {
             $this->response = array('errorMessage' => $fileName . $e->getMessage());
             return FALSE;
         }
     } else {
         $this->response = array('errorMessage' => $result['error']);
         return FALSE;
     }
 }
Example #2
0
 /**
  * 更新LOGO
  *
  * @return bool
  */
 public function updateLogo()
 {
     if (!isset($_FILES['qqfile'])) {
         return true;
     }
     $uploader = new FileUploader();
     $result = $uploader->handleUpload('brand');
     if (isset($result['success'])) {
         if ($this->id_image > 0) {
             $image = new Image($this->id_image);
             if (Validate::isLoadedObject($image)) {
                 $image->delete();
             }
         }
         $this->id_image = $result['success']['id_image'];
         return $this->update();
     }
     return false;
 }
Example #3
0
/**
 * 上传图片并更新排序
 */
function ajaxProcessAddImage()
{
    // max file size in bytes
    $uploader = new FileUploader();
    $result = $uploader->handleUpload(ImageType::IMAGE_PRDOCUT);
    if (isset($result['success'])) {
        $image = $result['success'];
        $row['id_product'] = Tools::Q('id_product');
        $row['id_image'] = (int) $image['id_image'];
        $row['position'] = (int) Product::getImageLastPosition($row['id_product']);
        if ($row['position'] == 1) {
            $row['cover'] = 1;
        } else {
            $row['cover'] = 0;
        }
        Db::getInstance()->insert(DB_PREFIX . 'product_to_image', $row);
        $json = array('status' => 'ok', 'id' => $row['id_image'], 'path' => Image::getImageLink($row['id_image'], 'small'), 'position' => $row['position'], 'cover' => $row['cover']);
        die(json_encode($json));
    } else {
        die(json_encode($result));
    }
}
 public function run()
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . $this->tempFolder;
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     $uploader = new FileUploader($this->allowedFileExtensions, $this->fileLimit);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             // if min/max weight/height are set - check those conditions
             $this->validateImageDimensions($imageHandler->getWidth(), $imageHandler->getHeight());
             $this->getController()->successfulAjaxResponse(array('fileName' => $imageHandler->getBaseFileName(), 'imageSrc' => '/application' . $this->tempFolder . $imageHandler->getBaseFileName()));
         } catch (CException $e) {
             $errorMsg = $imageHandler->getBaseFileName() . ' - ' . $e->getMessage();
             $this->getController()->unsuccessfulAjaxResponse(array('errorMessage' => $errorMsg));
         }
     } else {
         $this->getController()->unsuccessfulAjaxResponse(array('errorMessage' => $result['error']));
     }
 }
Example #5
0
 /**
  * Upload and apply new avatar
  * @return bool
  * @throws CException
  */
 public function changeAvatar()
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     $avatarsFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['userAvatars'];
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     // Upload to temp folder
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         // Move file to target folder and make thumbs
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         try {
             $imageHandler->save($avatarsFolder . $result['filename']);
             $imageHandler->cropAndScaleFromCenter(self::SMALL_THUMB_WIDTH, self::SMALL_THUMB_HEIGHT);
             $imageHandler->save($avatarsFolder . self::THUMB_PREFIX_SMALL . $result['filename']);
             $imageHandler->load($tempFolder . $result['filename']);
             $imageHandler->cropAndScaleFromCenter(self::MICRO_THUMB_WIDTH, self::MICRO_THUMB_HEIGHT);
             $imageHandler->save($avatarsFolder . self::THUMB_PREFIX_MICRO . $result['filename']);
             if ($this->hasPhoto()) {
                 $this->_removeOldPhoto();
             }
             $this->photo = $result['filename'];
             $this->_response = array('originalSrc' => $this->getOriginalPhoto(), 'thumbSrc' => $this->getSmallThumbnail());
             $this->save(FALSE);
             return TRUE;
         } catch (CException $e) {
             $this->_response = array('errorMessage' => $e->getMessage());
             return FALSE;
         }
     } else {
         $this->_response = array('errorMessage' => $result['error']);
         return FALSE;
     }
 }
 public function ajaxProcessAddImage()
 {
     self::$currentIndex = 'index.php?tab=AdminProducts';
     $allowedExtensions = array('jpeg', 'gif', 'png', 'jpg');
     // max file size in bytes
     $uploader = new FileUploader($allowedExtensions, $this->max_image_size);
     $result = $uploader->handleUpload();
     if (isset($result['success'])) {
         $obj = new Image((int) $result['success']['id_image']);
         // Associate image to shop from context
         $shops = Shop::getContextListShopID();
         $obj->associateTo($shops);
         $json_shops = array();
         foreach ($shops as $id_shop) {
             $json_shops[$id_shop] = true;
         }
         $json = array('name' => $result['success']['name'], 'status' => 'ok', 'id' => $obj->id, 'path' => $obj->getExistingImgPath(), 'position' => $obj->position, 'cover' => $obj->cover, 'shops' => $json_shops);
         @unlink(_PS_TMP_IMG_DIR_ . 'product_' . (int) $obj->id_product . '.jpg');
         @unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $obj->id_product . '_' . $this->context->shop->id . '.jpg');
         die(Tools::jsonEncode($json));
     } else {
         die(Tools::jsonEncode($result));
     }
 }
Example #7
0
 /**
  * Handle the XHR upload request and return the results 
  * 
  * @param string $filename
  */
 function upload_sale_pic($filename)
 {
     require_once APPPATH . 'libraries/FileUploader' . EXT;
     $allowedExtensions = array("jpeg", "bmp", "jpg", "png", "gif");
     // max file size in bytes
     $sizeLimit = 6 * 1024 * 1024;
     $uploader = new FileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload('./img/' . $this->phpsession->get('current_domain')->getTag() . '/uploads/', FALSE, $filename);
     // to pass data through iframe you will need to encode all html tags
     echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
 }
Example #8
0
 /**
  * Enregistre le fichier envoyé en local
  *
  * @param string   $uploadDirectory   -> Le chemin du dossier de destination
  * @param bool     $replaceOldFile    -> Remplacement des anciens fichiers qui ont le même nom ? Non par défaut
  * @param array    $allowedExtensions -> Les extensions autorisées : array('jpg', 'png', 'gif');
  * @param int      $sizeLimit         -> La taille limite d'envoi (égale ou inférieure à la configuration de PHP)
  * @param function $filenameFunction  -> La fonction de traitement du filename
  * @return array('success' => true) ou array('error' => 'error message')
  */
 public static function saveUploadedFile($uploadDirectory, $replaceOldFile = false, $allowedExtensions = array(), $sizeLimit = 10485760, $filenameFunction = null)
 {
     $uploader = new FileUploader($allowedExtensions, $sizeLimit);
     return $uploader->handleUpload($uploadDirectory, $replaceOldFile, $filenameFunction);
 }
Example #9
0
 /**
  * Handle the XHR upload request and return the results 
  * 
  * @param string $filename
  */
 function uploadcustomimage($filename, $owned_item_id)
 {
     require_once APPPATH . 'libraries/FileUploader' . EXT;
     /* @var $oiVO OwnedItemVO */
     $oiVO = $this->getOwnedItems(array($owned_item_id), false, false, true);
     $oiVO = current($oiVO);
     if ($oiVO->getPerson_id() != $this->phpsession->get('personVO')->getPerson_id()) {
         return false;
     }
     $allowedExtensions = array("jpeg", "bmp", "jpg", "png", "gif");
     // max file size in bytes
     $sizeLimit = 6 * 1024 * 1024;
     $uploader = new FileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload('./img/' . $this->phpsession->get('current_domain')->getTag() . '/uploads/', FALSE, $filename);
     // to pass data through iframe you will need to encode all html tags
     //echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
     $filename = $result['filename'];
     $this->load->library('image_lib');
     $config['image_library'] = 'gd2';
     $config['source_image'] = './img/' . $this->phpsession->get('current_domain')->getTag() . '/uploads/' . $filename;
     $config['new_image'] = './img/' . $this->phpsession->get('current_domain')->getTag() . '/customs/' . $filename;
     //initialize first to get the dimensions
     $this->image_lib->initialize($config);
     $config['width'] = "200";
     $config['maintain_ratio'] = TRUE;
     //load width and ratio setting to resize image to 200px wide
     $this->image_lib->initialize($config);
     $this->image_lib->resize();
     $this->image_lib->clear();
     $this->image_lib->initialize($config);
     $config['image_library'] = 'gd2';
     $config['source_image'] = './img/' . $this->phpsession->get('current_domain')->getTag() . '/customs/' . $filename;
     $config['new_image'] = './img/' . $this->phpsession->get('current_domain')->getTag() . '/thumbs/150/customs/' . $filename;
     //initialize first to get the dimensions
     $this->image_lib->initialize($config);
     $config['width'] = "150";
     $config['maintain_ratio'] = TRUE;
     //load width and ratio setting to resize image to 200px wide
     $this->image_lib->initialize($config);
     $this->image_lib->resize();
     $this->image_lib->clear();
     $config['image_library'] = 'gd2';
     $config['source_image'] = './img/' . $this->phpsession->get('current_domain')->getTag() . '/customs/' . $filename;
     $config['new_image'] = './img/' . $this->phpsession->get('current_domain')->getTag() . '/thumbs/100/customs/' . $filename;
     //initialize first to get the dimensions
     $this->image_lib->initialize($config);
     $config['width'] = "100";
     $config['maintain_ratio'] = TRUE;
     //load width and ratio setting to resize image to 200px wide
     $this->image_lib->initialize($config);
     if (!$this->image_lib->resize()) {
         echo $this->image_lib->display_errors();
         return;
     } else {
         //save custom image filename and delete original uploaded pic
         $old_img = $oiVO->getcustImg();
         $oiVO->setcustImg($filename);
         $oiVO->Save();
         if ($old_img != 'stock') {
             @unlink('./img/' . $this->phpsession->get('current_domain')->getTag() . '/customs/' . $old_img);
         }
         unlink('./img/' . $this->phpsession->get('current_domain')->getTag() . '/uploads/' . $filename);
         echo json_encode($result);
     }
 }
Example #10
0
 /**
  * Enregistre le fichier envoyé en local
  *
  * @param string   $uploadDirectory   -> Le chemin du dossier de destination
  * @param bool     $replaceOldFile    -> Remplacement des anciens fichiers qui ont le même nom ? Non par défaut
  * @param array    $allowedExtensions -> Les extensions autorisées : array('jpg', 'png', 'gif');
  * @param int      $sizeLimit         -> La taille limite d'envoi (égale ou inférieure à la configuration de PHP)
  * @param function $filename_function -> La fonction de traitement du filename
  * @return array('success' => true) ou array('error' => 'error message')
  */
 public static function saveUploadedFile($uploadDirectory, $replaceOldFile = false, $allowedExtensions = array(), $sizeLimit = 10485760, $filename_function = null)
 {
     // Initialisation de la classe et enregistrement du fichier
     $uploader = new FileUploader($allowedExtensions, $sizeLimit);
     $result = $uploader->handleUpload($uploadDirectory, $replaceOldFile, $filename_function);
     // Retourne le résultat en json
     return htmlspecialchars(json_encode($result), ENT_NOQUOTES);
 }
Example #11
0
File: up.php Project: liary/KitJs
        }
        $pathinfo = pathinfo($this->file->getName());
        $filename = $pathinfo['filename'];
        //$filename = md5(uniqid());
        $ext = $pathinfo['extension'];
        if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
            $these = implode(', ', $this->allowedExtensions);
            return array('error' => 'File has an invalid extension, it should be one of ' . $these . '.');
        }
        if (!$replaceOldFile) {
            /// don't overwrite previous files that were uploaded
            while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
                $filename .= rand(10, 99);
            }
        }
        if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) {
            return array('success' => true, 'url' => 'http://server-ip/KitJs/KitJs/demo/Upload/Uploads/' . $filename . '.' . $ext);
        } else {
            return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered');
        }
    }
}
// list of valid extensions, ex. array("jpeg", "xml", "bmp")
$allowedExtensions = array();
//最大上传大小
$sizeLimit = 1000 * 1024 * 1024;
$uploader = new FileUploader($allowedExtensions, $sizeLimit);
// 上传目录设置
$result = $uploader->handleUpload('uploads/');
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
Example #12
0
 /**
  * Upload and apply new avatar
  * @return bool
  * @throws CException
  */
 public static function uploadPhoto($userId)
 {
     // folder for uploaded files
     $tempFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['temp'];
     $photosFolder = Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . Yii::app()->params['folders']['userPhotos'];
     $photosFolder .= $userId . DIRECTORY_SEPARATOR;
     if (!is_writable($tempFolder)) {
         throw new CException('temporary folder is not exists or not writable. Path:' . $tempFolder);
     }
     // Upload to temp folder
     $uploader = new FileUploader(Yii::app()->params['uploader']['allowedFileExtensions'], Yii::app()->params['uploader']['sizeLimit']);
     $result = $uploader->handleUpload($tempFolder);
     if (!isset($result['error'])) {
         // Move file to target folder and make thumbs
         $imageHandler = new CImageHandler();
         $imageHandler->load($tempFolder . $result['filename']);
         $imageHandler->save($photosFolder . $result['filename']);
         $imageHandler->cropAndScaleFromCenter(300, 300);
         $imageHandler->save($photosFolder . self::THUMB_PREFIX_SMALL . $result['filename']);
         $model = new Photos();
         $model->owner_id = $userId;
         $model->file_name = $result['filename'];
         $model->save();
         return array('originalSrc' => $model->getOriginal(), 'thumbSrc' => $model->getSmallThumbnail(), 'photoId' => $model->id);
     } else {
         throw new CException($result['error']);
     }
 }