Implementing file upload progress with Zend

2019-03-31 08:12发布

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

Thanks.

1条回答
趁早两清
2楼-- · 2019-03-31 09:06

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...

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)


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.

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.


Now that you form is OK, you can finally take a look at Zend_ProgressBar, and at the documentation chapter that describes Progress for file uploads

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);
}

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


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

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 :


Hope this helps at least a bit ;-)

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 ;-)

查看更多
登录 后发表回答