2012-12-27 1 views
2

젠드 프레임 워크에서 이미지 크기를 조절하기 위해 http://eliteinformatiker.de/2011/09/02/thumbnails-upload-and-resize-images-with-zend_form_element_file/을 사용하고 있습니다.Skoch의 크기 조정 시스템은 어떻게 작동합니까?

하지만 실제로는 에서 작동하지 않습니다.

내 코드 :

내 젠드 양식

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

모든 솔루션?

감사합니다.


발견되었습니다.

당신의 젠드 양식이 교체 기준 :

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

,

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

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 
     ))); 
+0

이미 유래에 대한 답변을 추가 할 수 있습니다 (나는 경우 확실하지 않다 새로운 사용자는 그것을 할 수 있습니까?) 그렇다면 솔루션을 응답 영역에 복사하고 ** 사용자의 대답을 수락하십시오 **. 그건 stackoverflow 방법 :) – Aufziehvogel

답변

1

내가 너무 사람들이 당신에 의해 발견 대답을 추가 이 질문에 답을 얻었습니다.

발견되었습니다.

당신의 젠드 양식이 교체 기준 :

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

,

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

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