File Upload using zend framework 1.7.4(使用 Zend 框架 1.7.4 上传文件)
问题描述
我正在尝试使用 Zend Framework 1.7.4 上传文件,但没有成功.我已经阅读了 Akrabat 的教程,这很有帮助,但是当我在我的项目中使用这些技术时,我无法让它工作.
I am trying to upload a file using Zend Framework 1.7.4, but have not been successful. I have read Akrabat's tutorial, which was helpful but when i used those techniques in my project I was not able to get it to work.
推荐答案
您发布的链接只是一般的 Zend Framework 教程,在 ZF 1.5 之后尚未更新.
The link you posted is just a general Zend Framework tutorial, and hasn't been updated past ZF 1.5.
无论如何,一旦您开始使用 Zend,这是您用来接收上传的代码示例.进行发布的表单必须具有正确的文件上传组件.
Anyway, once you get started with Zend, this is a sample of the code you would use to receive an upload. The form doing the posting must have the correct file upload components.
//validate file
//for example, this checks there is exactly 1 file, it is a jpeg and is less than 512KB
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addValidator('Count', false, array('min' =>1, 'max' => 1))
->addValidator('IsImage', false, 'jpeg')
->addValidator('Size', false, array('max' => '512kB'))
->setDestination('/tmp');
if (!$upload->isValid())
{
throw new Exception('Bad image data: '.implode(',', $upload->getMessages()));
}
try {
$upload->receive();
}
catch (Zend_File_Transfer_Exception $e)
{
throw new Exception('Bad image data: '.$e->getMessage());
}
//then process your file, it's path is found by calling $upload->getFilename()
这篇关于使用 Zend 框架 1.7.4 上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Zend 框架 1.7.4 上传文件
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01