我有一个Zend表单并提供了使用表单上传多个文件的选项。我使用dropzone.js。当我上传一个文件,一切正常,我得到Post数据,文件被重命名并移动到正确的文件夹,但是我上传2个文件后,我收到一条错误信息:注意:数组到字符串转化,指向$ upload-> addFilters('文件\重命名' .....
我在这里做错了什么?我在foreach循环中拥有一切,如果这不能解决问题?我无法找到解决方案。有人给我一个小费?
到目前为止我的源代码:
$upload = new \Zend\File\Transfer\Adapter\Http();
// Limit the amount of files
$upload->addValidator('Count', false, 2);
// Limit the MIME type of all given files to gif and jpeg images
$upload->addValidator('MimeType', false, array('image/gif', 'image/jpeg',));
if (!$upload->isValid()) {
$data = new JsonModel(array(
'success' => "failed",
'message' => "validation failed",
));
return $data;
}else{
$files = $upload->getFileInfo();
$upload->setDestination('./public/uploads/tmp/');
// loop through the file array
foreach ($files as $file => $info) {
$file_ext = @strtolower(@strrchr($originalName,"."));
$file_ext = @substr($file_ext, 1); // remove dot
$newFilename = md5(uniqid(rand(), true)) .time(). '.' . $file_ext;
$upload->addFilter('File\Rename',
array('target' => $upload->getDestination() . DIRECTORY_SEPARATOR . $newFilename,
'overwrite' => true));
if (!$upload->receive()) {
$data = new JsonModel(array(
'success' => "upload failed",
));
}else{
$data = new JsonModel(array(
'success' => "upload ok",
));
}
return $data;
} // end foreach
}