Reputation: 735
I would to like to implement multiple file upload. I am getting this code only single file is uploading. How to implement multiple file upload
Form Code
$docupload=new Zend_Form_Element_File('docupload',array('multiple' => 'multiple'));
$docupload->addValidator(new Zend_Validate_File_Extension('doc,docx,pdf,txt'));
$docupload->setIsArray(true);
In Controller
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);
}
I am new to zend framework. Please help me.Thanks in advance
Upvotes: 1
Views: 440
Reputation: 1103
Rather than use the $_FILES variable, it would be better to use the applicable Zend code, considering that you're using Zend as your framework:
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
Upvotes: 1