2012-04-18 143 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