你好我有以下设置,调整到ZF2FileUploadExamples上的ZF2FileUpload示例 控制器:
public function addAction()
{
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
$form = new CreateEventForm($objectManager);
$event = new Event();
$form->bind($event);
if ($this->getRequest()->isPost())
{
// Merge the files
$post = array_merge_recursive(
$this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid())
{
return $this->redirectToSuccessPage($form->getData());
}
return new ViewModel(array(
'event' => $event,
'form' => $form
));
}
InputFilter文件过滤器部分:
private function addFile()
{
$name = '/event';
$path = APPLICATION_PATH . '/../data/upload/';
$target = realpath($path) . $name;
// File Input
$input = new FileInput('image');
$input->setRequired(TRUE);
$input->setAllowEmpty(FALSE);
// Filters
$renameUpload = new RenameUpload($target);
$renameUpload->setOverwrite(FALSE);
$renameUpload->setUseUploadExtension(TRUE);
$renameUpload->setUseUploadName(TRUE);
$renameUpload->setRandomize(TRUE);
// File Input
$input->getFilterChain()->attach($renameUpload);
//Validators
$this->add($input);
return $this;
}
在成功页面的转储中我看到:
文件上传成功
object(Entities\Event)[323]
private 'id' => null
private 'title' => string 'Event10' (length=7)
private 'eventinfo' => string 'Event 10' (length=8)
private 'image' =>
array (size=1)
0 =>
array (size=5)
'name' => string 'test.jpg' (length=38)
'type' => string 'image/jpeg' (length=10)
'tmp_name' => string '/tmp/phpjWIZWS' (length=14)
'error' => int 0
'size' => int 257860
private 'eventdate' =>
object(DateTime)[324]
public 'date' => string '2015-04-11 00:00:00' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Berlin' (length=13)
private 'webshop' => null
- 编辑 - Wilt你在正确的轨道上,我的InputFilter从未被调用过。现在它似乎被调用,但我返回到Form并生成消息No Files Selected
有什么建议吗?
我有两个问题: