使用 Zend 实现文件上传进度 [英] Implementing file upload progress with Zend

查看:23
本文介绍了使用 Zend 实现文件上传进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Zend 实现上传进度,但是我还没有找到任何详细的教程.一个指针会很有用.

Hi Im attempting to implement upload progress with Zend however I havent found any detailed tutorials. A pointer would be useful.

谢谢.

推荐答案

我不记得曾经看过完整详细的教程,解释如何使用 Zend Framework 获取上传进度条;但这里有一些提示,如果您已经了解有关 PHP、文件上传和 Zend 框架的一些知识,它们应该可以对您有所指导......

I don't remember having ever seen a fully-detailled tutorial explaining how to get a progress bar for uploads with Zend Framework ; but here are a few pointers, that should guide you a bit, provided you already know so stuff about PHP, file uploads, and Zend Framework...

首先,您需要安装这两个 PHP 扩展之一:

First of all, you'll need one of those two PHP extension installed :

这意味着只有当您是服务器的管理员时,您才能获得那种进度条(默认情况下通常不会安装这些扩展程序 -- 并且不在共享主机上)

Which mean you'll be able to get that kind of progress bar only if you are admin of your server (those kind of extensions are generally not installed by default -- and not on shared hosting)


然后,您必须在上传表单中使用一些特殊的隐藏"字段;关于这一点,您可以查看 配置选项APC ;尤其是与 RFC 1867 相关的那些.


Then, you have to use some special "hidden" fields in your upload form ; about that, you can take a look at the configuration options of APC ; especially those related to RFC 1867.

如果您正在使用 Zend Framework,我想您已经在使用一些 Zend_Form_Element_File 在您的表单中.它应该已经对这些字段做了必要的事情——顺便说一句,你最好检查一下.

If you are using Zend Framework, I suppose you are already using some Zend_Form_Element_File in your form. It should already do what is necessary about those fields -- you'd better check that, to be sure, btw.


现在你的表格已经OK了,你终于可以看看Zend_ProgressBar,以及文档章节描述文件上传进度

您的代码可能看起来有点像这样(引用文档):

Your code will probably look a bit like this (quoting the doc) :

$adapter = new Zend_ProgressBar_Adapter_Console();
$upload  = Zend_File_Transfer_Adapter_Http::getProgress($adapter);

$upload = null;
while (!$upload['done']) {
    $upload = Zend_File_Transfer_Adapter_Http:getProgress($upload);
}

而且,要定期获取该信息,您必须使用某种 Ajax 请求从网页进行一些轮询.

And, to fetch that information regularly, you'll have to do some polling from the web page, using some kind of Ajax requests.


关于uploadprogress扩展,可以看看这些文章:


About the uploadprogress extension, you can take a look at these articles :

  • Upload Progress Meter - Common issues and some answers -- it might give you a few pointers.
  • AJAX File upload Progress and PHP AJAX File Upload Progress Meter Updates
  • Upload Progress Meter extension for PHP 5.2

这些帖子并不是专门针对 Zend Framework,但可能会让您了解正在发生的事情 ;-)

Those posts are not specifically targetting Zend Framework, but might give you an idea of what is going on ;-)


顺便说一句,您可能想在本地机器上测试所有这些,这更容易开发……这意味着文件上传确实快速;这不太适合测试任何类型的进度上传指标...


BTW, you'll probably want to test all that on your local machine, which is easier to develop... And that will mean that file upload will really be fast ; which is not quite good to test any kind of progress upload indicator...

关于这一点,您可能会对减慢"本地网络接口的速度感兴趣;这些可能会有所帮助:

About that, you might be interesting in "slowing down" your local network interface ; those might help :


希望这至少有一点帮助;-)

而且,当你在做的时候:你为什么不把你的发现写成一些很好的和详细的教程?这可能对某些人有用;-)

And, while you're at it : why don't you write down your findings into some kind of nice and detailled tutorial ? That might be useful to some people ;-)

这篇关于使用 Zend 实现文件上传进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆