【问题标题】:How Skoch's resizing system works?Skoch 的大小调整系统如何工作?
【发布时间】:2012-12-27 11:42:23
【问题描述】:

我正在使用 http://eliteinformatiker.de/2011/09/02/thumbnails-upload-and-resize-images-with-zend_form_element_file/ 在 Zend Framework 中调整图像大小。

但实际上,它不适用于receive()

我的代码:

我的 Zend 表单

class Application_Form_Admin_Photos_Ajout extends Zend_Form
{
   public function init()
    {        


        /**
         * FILE
         */
        $this->setAttrib('enctype', 'multipart/form-data');
        $maxsize = 2 * 1024 * 1024; // Premier chiffre en MB
        $file = new Zend_Form_Element_File('path');
        $file->setLabel("Choisissez l'image");
        $file->setMaxFileSize($maxsize);
        $file->addValidator('Count', false, 1);
        $file->addValidator('Size', false, $maxsize);
        $file->addValidator('Extension', false, 'jpg,png,gif');
        $file->setRequired(true);
        $this->addElement($file);



        /**
         * LEGENDE
         */
[...]


        /**
         * SUBMIT
         */
[...]
    }

}

我的控制器:

    if ($request->isPost())
    {
        if ($form->isValid($request->getPost()))
        {
            $file = pathinfo($form->path->getFileName());
            $path = Zend_Registry::get('config')->imgPath . uniqid() . time() . '.' . $file['extension'];
            $form->getElement('path')->addFilter('Rename', array('target' => $path,'overwrite' => true));
            $filterChain = new Zend_Filter();
            // Create the original one
            $filterChain->appendFilter(new Skoch_Filter_File_Resize(array(
                'directory' => Zend_Registry::get('config')->imgPath,
                'width' => 10000,
                'height' => 10000,
                'keepSmaller' => true
            )));
            // Create a medium image with at most 350x200 pixels
            $filterChain->appendFilter(new Skoch_Filter_File_Resize(array(
                'directory' => Zend_Registry::get('config')->thumbPath,
                'width' => 350,
                'height' => 200,
                'keepRatio' => true,
            )));
            $form->getElement('path')->addFilter($filterChain);
            if (!$form->path->receive())
                $this->_redirect('/admin/menu/menu');
        }
    }

有什么办法吗?

谢谢。


我找到了。

在 Zend 表单中替换它:

$file->addValidator('Count', false, 1);

由,

$file->addValidator('Count', false, 2);

2 表示您的 Zend Form 最多接受 2 个文件。 (http://framework.zend.com/manual/1.12/en/zend.file.transfer.validators.html#zend.file.transfer.validators.count)

另一种解决方案,只需删除该行,

$file->addValidator('Count', false, 1);

而且这个,不是很有用:

 $filterChain->appendFilter(new Skoch_Filter_File_Resize(array(
            'directory' => Zend_Registry::get('config')->imgPath,
            'width' => 10000,
            'height' => 10000,
            'keepSmaller' => true
        )));

【问题讨论】:

  • 你可以添加答案到stackoverflow吗(我不确定新用户是否可以这样做)?如果是,请将您的解决方案复制到答案区域并接受您自己的答案。这就是stackoverflow的方式:)

标签: image zend-framework zend-form image-resizing


【解决方案1】:

我只是添加您找到的答案,以便人们知道这个问题已得到解答。

我找到了。

在你的 Zend 表单中替换它:

$file->addValidator('Count', false, 1);

由,

$file->addValidator('Count', false, 2);

其中 2 表示您的 Zend Form 最多接受 2 个文件。 (http://framework.zend.com/manual/1.12/en/zend.file.transfer.validators.html#zend.file.transfer.validators.count)

另一种解决方案,只需删除该行,

$file->addValidator('Count', false, 1);

而且这个,不是很有用:

$filterChain->appendFilter(new Skoch_Filter_File_Resize(array(
            'directory' => Zend_Registry::get('config')->imgPath,
            'width' => 10000,
            'height' => 10000,
            'keepSmaller' => true
        )));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 2015-07-27
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多