1

I can upload the image and resize with phpthumb, but how can i also have the original image uploaded too?

     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;
            }

My forms look like this

$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);

Please help me how to upload multiple thumbnail or how can i get the original file uploaded as well ? Thanks

4

1 回答 1

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());
于 2012-04-18T03:00:09.467 回答