Ejemplo n.º 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);
 }
Ejemplo n.º 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);
 }