Beispiel #1
0
 public static function file(UploadedFile $fileInstance, $dir = '', $namePostfix = true)
 {
     $fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . Upload::getFileName($fileInstance, $namePostfix);
     if (!$fileInstance->saveAs($fileName)) {
         throw new HttpException(500, 'Cannot upload file "' . $fileName . '". Please check write permissions.');
     }
     return Upload::getLink($fileName);
 }
Beispiel #2
0
 public static function upload(UploadedFile $fileInstance, $dir = '', $resizeWidth = null, $resizeHeight = null, $resizeCrop = false)
 {
     $fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . Upload::getFileName($fileInstance);
     $uploaded = $resizeWidth ? self::copyResizedImage($fileInstance->tempName, $fileName, $resizeWidth, $resizeHeight, $resizeCrop) : $fileInstance->saveAs($fileName);
     if (!$uploaded) {
         throw new HttpException(500, 'Cannot upload file "' . $fileName . '". Please check write permissions.');
     }
     return Upload::getLink($fileName);
 }
Beispiel #3
0
 static function createThumbnail($fileName, $width, $height = null, $crop = true)
 {
     $fileName = str_replace(Url::base(true), '', $fileName);
     $webRoot = Yii::getAlias('@webroot');
     if (!strstr($fileName, $webRoot)) {
         $fileName = $webRoot . $fileName;
     }
     $thumbFolder = dirname($fileName) . DIRECTORY_SEPARATOR . ($width . ($height ? 'x' . $height : ''));
     $thumbFile = $thumbFolder . DIRECTORY_SEPARATOR . basename($fileName);
     if (!FileHelper::createDirectory($thumbFolder)) {
         throw new HttpException(500, 'Cannot create "' . $thumbFolder . '". Please check write permissions.');
     }
     return self::copyResizedImage($fileName, $thumbFile, $width, $height, $crop) ? Upload::getLink($thumbFile) : false;
 }
Beispiel #4
0
 public static function upload(UploadedFile $fileInstance, $dir = '', $resizeWidth = null, $resizeHeight = null, $resizeCrop = false)
 {
     $fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . Upload::getFileName($fileInstance);
     $uploaded = $resizeWidth ? self::copyResizedImage($fileInstance->tempName, $fileName, $resizeWidth, $resizeHeight, $resizeCrop) : $fileInstance->saveAs($fileName);
     if (!$uploaded) {
         throw new HttpException(500, 'Cannot upload file "' . $fileName . '". Please check write permissions.');
     }
     if (@exif_imagetype($fileName) === IMAGETYPE_GIF) {
         $frameFileName = $fileName . '.frame.png';
         $image = new Imagick($fileName);
         $image = $image->coalesceImages();
         foreach ($image as $frame) {
             $frame->setImageFormat('png');
             $frame->writeImage($frameFileName);
             return Upload::getLink($frameFileName);
         }
     }
     return Upload::getLink($fileName);
 }