コード例 #1
0
ファイル: FtpManager.php プロジェクト: mclkim/webftp
 public function generateThumbnail($thumbnailInfo, $thumbnailParams = null)
 {
     $publicUrl = '_thumbnail/';
     $tempFilePath = null;
     $thumbnailPath = null;
     try {
         // Get and validate input data
         $path = $thumbnailInfo['path'];
         $width = $thumbnailInfo['width'];
         $height = $thumbnailInfo['height'];
         $lastModified = $thumbnailInfo['lastModified'];
         if (!is_numeric($width) || !is_numeric($height) || !is_numeric($lastModified)) {
             throw new ApplicationException('Invalid input data');
         }
         if (!$thumbnailParams) {
             $thumbnailParams = $this->getThumbnailParams();
             $thumbnailParams['width'] = $width;
             $thumbnailParams['height'] = $height;
         }
         // If the thumbnail file exists - just return the thumbnail marup,
         // otherwise generate a new thumbnail.
         $thumbnailPath = $this->getThumbnailImagePath($thumbnailParams, $path, $lastModified);
         if ($this->thumbnailExists($thumbnailPath)) {
             return ['isError' => false, 'imageUrl' => $publicUrl . FtpLibraryItem::getInstance()->getbasename($thumbnailPath)];
         }
         // Save the file locally
         $tempFilePath = $this->getLocalTempFilePath();
         if (!$this->downloadFile($path, $tempFilePath)) {
             throw new SystemException('Error saving remote file to a temporary location');
         }
         // Resize the thumbnail and save to the thumbnails directory
         $this->resizeImage($tempFilePath, $thumbnailParams, $thumbnailPath);
     } catch (Exception $ex) {
         // $this->err ( $ex->getMessage () );
         return ['isError' => true];
     }
     return ['isError' => false, 'imageUrl' => $publicUrl . FtpLibraryItem::getInstance()->getbasename($thumbnailPath)];
 }
コード例 #2
0
ファイル: FtpLibrary.php プロジェクト: mclkim/webftp
 public function downloadFile($path = '/', $tempfile, $mode = 'auto')
 {
     $fullpath = self::validatePath($path);
     $path = dirname($fullpath);
     $file = FtpLibraryItem::getInstance()->getbasename($fullpath);
     // Set the mode if not specified
     if ($mode === 'auto') {
         $extension = FtpLibraryItem::getInstance()->getextension($file);
         $mode = FtpLibraryItem::getInstance()->getFileMode($extension);
     }
     try {
         $this->ftp->chdir($path);
         $mode = $mode === 'ascii' ? FTP_ASCII : FTP_BINARY;
         $this->ftp->get($tempfile, $file, $mode);
     } catch (Exception $e) {
         throw new FtpException($e->getMessage());
         return false;
     }
     return true;
 }