我使用http://eliteinformatiker.de/2011/09/02/thumbnails-upload-and-resize-images-with-zend_form_element_file/在Zend Framework中調整圖像大小。Skoch的大小調整系統如何工作?
但實際上,它不適用於。
我的代碼:
我的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
*/
[...]
}
}
myController的:
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形式接受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的方式:) – Aufziehvogel