Upload Progress Bar in PHP

前端 未结 10 1348
栀梦
栀梦 2020-11-22 17:33

Does anyone know how to get a progress bar for an upload in php? I am trying writing code for a photo album uploader. I would like a progress bar to display while the photos

相关标签:
10条回答
  • 2020-11-22 17:49

    HTML5 introduced a file upload api that allows you to monitor the progress of file uploads but for older browsers there's plupload a framework that specifically made to monitor file uploads and give information about them. plus it has plenty of callbacks so it can work across all browsers

    0 讨论(0)
  • 2020-11-22 17:53

    I'm sorry to say that to the best of my knowledge a pure PHP upload progress bar, or even a PHP/Javascript upload progress bar is not possible because of how PHP works. Your best bet is to use some form of Flash uploader.

    AFAIK This is because your script is not executed until all the superglobals are populated, which includes $_FILES. By the time your PHP script gets called, the file is fully uploaded.

    EDIT: This is no longer true. It was in 2010.

    0 讨论(0)
  • 2020-11-22 17:54

    This is by far (after hours of googling and trying scripts) the simplest to set up and nicest uploader I've found

    https://github.com/FineUploader/fine-uploader

    It doesn't require APC or any other external PHP libraries, I can get file progress feedback on a shared host, and it claims to support html5 drag and drop (personally untested) and multiple file uploads.

    0 讨论(0)
  • 2020-11-22 17:55

    A php/ajax progress bar can be done. (Checkout the Html_Ajax library in pear). However this requires installing a custom module into php.

    Other methods require using an iframe, through which php looks to see how much of the file has been uploaded. However this hidden iframe, may be blocked by some browsers addons because hidden iframes are often used to send malicious data to a users computer.

    Your best bet is to use some form of flash progress bar if you do not have control over your server.

    0 讨论(0)
提交回复
热议问题