2010-04-09 52 views
0

你好,我試圖創建一個Zend_Form的表單,這將使我的用戶能夠上傳一個無限數量的文件到我的網站,女巫是由JavaScript完成的。Zend表格和動態文件上傳

喜歡的東西

<script type="text/javascript"> 
$(document).ready(function(){ 
    var image_uploade_i = 0; 
    $('#upload_more').click(function() { 
     image_uploade_i++; 
     $('#upload_list').append('<div id="image_uploade_id_'+image_uploade_i+'" style="display: none;"><input type="file" name="image[]" /><br /></a>'); 
     $('#image_uploade_id_'+image_uploade_i).slideDown('slow'); 
    }); 
}); 
</script> 
<?=$this->translate('Add images')?> 
<form action="" method="post" enctype="multipart/form-data"> 
    <div id="upload_list"> 
     <input type="file" name="image[]" /><br /> 
     <input type="file" name="image[]" /><br /> 
     <input type="file" name="image[]" /><br /> 
    </div> 
    <a href="#" id="upload_more"><?=$this->translate('Upload another image')?></a><br /> 
    <input type="submit" name="image_uploade" value="<?=$this->translate('Upload images')?>" /> 
</form> 

但我是我無法找出如何我可以創建這樣的事情與Zend_From,我想用Zend_Form這個thoug的唯一理由是爲uploadet文件的驗證。

$element = new Zend_Form_Element_File('image'); 
    $element->setRequired(true) 
      ->setLabel('Profile image') 
      ->setDestination($store) 
      ->setValueDisabled(true) 
      ->addValidator(new Zend_Validate_File_ImageSize(array(
             'minheight' => 100, 'minwidth' => 150, 
             'maxheight' => 1920, 'maxwidth' => 1200))) 
      // File must be below 1.5 Mb 
      ->addValidator(new Zend_Validate_File_FilesSize(array('max' => 1572864))) 
      ->addValidator(new Zend_Validate_File_IsImage()); 

如果任何1可以幫我處理這件事了,我將是巨大的檸全:d

回答

1
$this->setAttrib('enctype', 'multipart/form-data'); 
$this->addElement('file', 'files', array(
    'label'   => 'Pictures', 
    'validators' => array(
     array('Count', false, array('min'=>1, 'max'=>3)), 
     array('Size', false, 102400), 
     array('Extension', false, 'jpg,png,gif') 
    ), 
    'multiFile'=>3, 
    'destination'=>APPLICATION_PATH . '/tmp' 
)); 

所以儘量setMultiFile並可能使用Count驗證爲了限制。

我從下面的源代碼編譯這個例子:http://framework.zend.com/manual/en/zend.form.standardElements.html#zend.form.standardElements.file

+0

謝謝你,這只是我一直在尋找的是:d – Androme 2010-04-10 14:27:01

+0

http://framework.zend.com/manual/en/zend.form.standardElements的.html#zend.form.standardElements.file – Ballsacian1 2010-04-10 15:21:48