2012-04-18 266 views
1

我可以上傳圖片並用phpthumb調整大小,但我怎樣才能也上傳原始圖片?phpthumb zend框架

 if ($this->getRequest()->isPost()) { 
     $formData = $this->getRequest()->getPost(); 
      if ($form->isValid($formData)) { 

      // upload the image 
      if ($form->station_image->isUploaded()) { 
       $form->station_image->receive(); 
       $station_image = '/upload/images/radio/' . basename($form->station_image->getFileName()); 
       //upload thumb 
       include_once '../library/PhpThumb/ThumbLib.inc.php'; 
        $thumb = PhpThumbFactory::create($form->station_image->getFileName());          
        $thumb->resize(50, 50)->save($form->station_image->getFileName()); 
        //thumb ends 



      }else{ 
       echo 'cannot upload'. exit; 
      } 

我的形式看起來像這樣

$station_image->setLabel('Upload File: ') 
         ->setDestination(APPLICATION_PATH.'/../public/upload/images/radio') 
         ->addValidator('Extension', false, 'jpg,png,gif') 
         ->addValidator('Size', false, 902400) 
         ->addValidator('Count', false, 1) 
         ->setRequired(false); 

請幫助我如何上傳多個縮略圖,或者我怎樣才能上傳以及原始文件?由於

回答

5

你是原始圖像傳遞到PHPThumb的構造函數:

$thumb = PhpThumbFactory::create($form->station_image->getFileName()); 

所以$form->station_image->getFileName()是原始文件。問題是你有過寫作與調整大小後的文件名的原始文件名,試試這個:

$thumb = PhpThumbFactory::create($form->station_image->getFileName());          
$thumb->resize(50, 50)->save('/path/where/you/want/resized/image/to/go.png'); 

- 更新 -

試試這個:

if ($form->station_image->isUploaded()) { 

    $form->station_image->receive(); 
    $station_image = '/upload/images/radio/' . basename($form->station_image->getFileName()); 
    //upload thumb 
    include_once '../library/PhpThumb/ThumbLib.inc.php'; 
    $thumb = PhpThumbFactory::create($form->station_image->getFileName()); 

    // Notice this is using $station_image, which I assume is an accessible path 
    // by your webserver          
    $thumb->resize(50, 50)->save($station_image); 
    //thumb ends 

}else{ 

- 更新 -

請嘗試更改此項:

$station_image = '/upload/images/radio/' . basename($form->station_image->getFileName()); 

要這樣:

$station_image = '/upload/images/radio/thumb_' . basename($form->station_image->getFileName()); 
+0

謝謝,但我怎麼設置相對路徑保存縮略圖?請幫助 – ktm 2012-04-18 09:17:37

+0

更新瞭解決方案。 – 2012-04-18 16:43:13

+0

它用來覆蓋原始圖像之前,現在它甚至不創建縮略圖。我想知道如果在窗體中設置目標是造成問題。 – ktm 2012-04-19 02:14:13