Php 使用Zend Framework上传图像?

Php 使用Zend Framework上传图像?,php,zend-framework,file-upload,Php,Zend Framework,File Upload,我想在Zend framework中上传一个图像 在Application\u Form\u Test.php中,我编写了以下代码 uploadImage = new Zend_Form_Element_File('uploadImage'); $uploadImage->setLabel("Upload Image ") ->setRequired(true) ->addValidator('Ext

我想在Zend framework中上传一个图像

在Application\u Form\u Test.php中,我编写了以下代码

uploadImage = new Zend_Form_Element_File('uploadImage');
$uploadImage->setLabel("Upload Image ")
            ->setRequired(true)               
            ->addValidator('Extension', false, 'jpeg,png')
            ->getValidator('Extension')->setMessage('This file type is not supportted.');
在testAction()中,我编写了以下代码

$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Size', false, 52428800, 'image');
$upload->setDestination('uploads');
$files = $upload->getFileInfo();
foreach ($files as $file => $info) {
    if ($upload->isValid($file)) {
         $upload->receive($file);
    }
}
代码正在成功运行,但我没有将该图像发送到目标文件夹

可能有什么问题。。。。? 请帮帮我


提前感谢….

我不认为getFileInfo()方法应该实际执行文件上传。我相信在控制器操作中,您必须对表单对象调用getValues()方法,或者对表单元素调用receiveFile()方法


有关文档示例,请参见。

另一个注意事项:如果查看
Zend\u Form\u Element\u File->receive()
,您将看到isValid()已被调用,因此无需将控制器与之混淆。我是这样做的:

if ($upload->receive()) {
    if ($upload->getFileName() && !file_exists($upload->getFileName())) {
        throw new Exception('The upload should have worked, but somehow did not!');
}
} else {
    throw new Exception(implode(PHP_EOL, $upload->getErrors()) . implode(PHP_EOL, $upload->getErrorMessages()));
}