如何在Zend Framework 2中上传多个文件。我已完成这项工作。但是,我在第二个文件中收到以下错误。
'first-filename' was illegally uploaded. This could be a possible attack.
供您参考,
$size = new Size(array('max' => 1048576));
$adapter= new \Zend\File\Transfer\Adapter\Http();
$File = $this->params()->fromFiles('logo');
$adapter->setValidators(array($size), $File['name']);
$FileName = '';
if (!$adapter->isValid()){
$dataError = $adapter->getMessages();
$error = array();
foreach($dataError as $key=>$row)
{
$error[] = $row;
}
} else {
$adapter->setDestination(path);
if ($adapter->receive($File['name'])) {
// manipulation
}
}
$logoFile = $this->params()->fromFiles('logo2');
$adapterLogo = new \Zend\File\Transfer\Adapter\Http();
$adapterLogo->setValidators(array($size), $logoFile['name']);
$logoFileName= '';
if (!$adapterLogo->isValid()){
$dataError = $adapterLogo->getMessages();
$error = array();
foreach($dataError as $key=>$row)
{
$error[] = $row;
}
} else {
$adapterLogo->setDestination(path2);
if ($adapterLogo->receive($logoFile['name'])) {
// manipulation
}
}
我该如何解决这个问题?为什么会出现此错误?
答案 0 :(得分:2)
您确定表单上有正确的加密类型吗?
$form->setAttribute('enctype','multipart/form-data');
将文件名添加到isValid检查中
if($adapterLogo->isValid('logo2')) { /** .. **/ }
如果使用Forms来为你重新设置这个比使用类似的验证器更简单,请参阅此示例:
http://samsonasik.wordpress.com/2012/08/31/zend-framework-2-creating-upload-form-file-validation/