首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >phpthumb框架

phpthumb框架
EN

Stack Overflow用户
提问于 2012-04-18 10:58:06
回答 1查看 526关注 0票数 1

我可以用phpthumb上传图片和调整大小,但我怎么也能上传原始图片呢?

代码语言:javascript
复制
     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;
            }

我的表单如下所示

代码语言:javascript
复制
$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);

请告诉我如何上传多个缩略图,或者我如何让原始文件也上传?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-18 11:00:09

您正在将原始图像传递给PHPThumb的构造函数:

代码语言:javascript
复制
$thumb = PhpThumbFactory::create($form->station_image->getFileName());

所以$form->station_image->getFileName()是你的原始文件。问题是您正在用调整大小的文件名覆盖原始文件名,请尝试以下操作:

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

-更新--

试一试:

代码语言:javascript
复制
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{

-更新--

尝试更改此设置:

代码语言:javascript
复制
 $station_image = '/upload/images/radio/' . basename($form->station_image->getFileName());

要这样做:

代码语言:javascript
复制
 $station_image = '/upload/images/radio/thumb_' . basename($form->station_image->getFileName());
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10202172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档