예제 #1
0
파일: Upload.php 프로젝트: tqsq2005/Yii2adv
 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);
 }
예제 #2
0
파일: Image.php 프로젝트: tqsq2005/Yii2adv
 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);
 }