[英]how to do multiple file upload in zend framework
我想實現多個文件上傳。 我正在獲取此代碼,只有單個文件正在上傳。 如何實現多文件上傳
表格代碼
$docupload=new Zend_Form_Element_File('docupload',array('multiple' => 'multiple'));
$docupload->addValidator(new Zend_Validate_File_Extension('doc,docx,pdf,txt'));
$docupload->setIsArray(true);
在控制器中
if(is_array($_FILES['docupload']['name']))
{
$params = $this->_form->getValues();
foreach($_FILES['docupload']['name'] as $key=>$files)
{
$file_name=$_FILES['docupload']['name'][$key];
$temp_image_path = $_FILES['docupload']['tmp_name'][$key];
$file_name=implode(",", $file_name);
$temp_image_path=implode(",", $temp_image_path);
['tmp_name'];
$path_parts = pathinfo($temp_image_path);
$tem_path = $path_parts['dirname'];
$path_parts_extension = pathinfo($file_name);
$actual_filename=$path_parts_extension['filename'];
$file_extension = $path_parts_extension['extension'];
if(APPLICATION_ENV != "development")
{
$path = '/';
}
else {
$path = '\\';
}
$filename = $tem_path.$path.$file_name;
$rename_uploadfile = $actual_filename.$random_number.".".$file_extension;
$fullFilePath = UPLOAD_USER_IMAGES.$rename_uploadfile;
// Rename uploaded file using Zend Framework
$filterFileRename = new Zend_Filter_File_Rename(array('target' => $fullFilePath));
$filterFileRename->filter($filename);
$form_data=$params;
$form_data['docupload']=$rename_uploadfile;
if($id)
{
$this->_table->updateById("id",$id, $form_data);
}
else
{
$this->_table->insert($form_data);
}
我是zend框架的新手。 請幫助我。謝謝
考慮到您將Zend用作框架,最好使用適用的Zend代碼,而不是使用$ _FILES變量:
if (!$form->isValid()) {
print "Uh oh... validation error";
}
if (!$form->docupload->receive()) {
print "Error receiving the file(s)";
}
$files = $form->docupload->getFileName(); // result should be an array in this case
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.