PHP file upload - Track bytes uploaded with AJAX - php

I'm trying to figure out if there's a way to get the progress of a file upload with PHP and/or Kohana. My script can upload images, videos, zip, exe, whatever I want really. However the larger the file the longer the user has to wait without any indication.
I was hoping to use some AJAX here to initialise the upload and then report back the progress.
Is this possible with PHP... and can anyone give me an indication of where to start looking.

there is a file upload progress extension for php, see http://www.ultramegatech.com/blog/2010/10/create-an-upload-progress-bar-with-php-and-jquery/ for how to use it.

I like to use a server module to do this sort of thing, mainly because it makes my life as a web developer easier if all I need to do is grab upload statistics from a URL. Nothing has to be changed in your website.
For Nginx there is the Upload Progress module and it should work on all recent releases. You can find code examples on the Nginx Wiki: http://wiki.nginx.org/HttpUploadProgressModule
For Apache there is the Upload Progress too. I haven't used it myself, but it seems fairly straight forward.
If you don't have access to the server configuration, then you might want to fall back onto a pure flash / javascript solution. For this I had good luck with Uploadify in the past, but it requires a bit more work as you now have to upload files in a separate request. Someone should be able to suggest a good HTML5 upload progress plugin too.

you could do this also with apache and APC example

Related

How do PHP and Apache handle uploaded files?

I am working on some PHP upload code.
When I call the copy function it will start a thread in incremental mod. I want to read the full details of the upload functionality for apache and PHP. In fact, I want implementation details for this functionality, namely:
How a file is copied in temp folder
How it is copied to the proper destination
What happens when server is busy and client is sending fix size of chunks
I am trying to upload file from my Android application. I am using this code for uploading. But my most of the files header are changed. Most of my uploaded files' sizes increase. Why its happen? In fact I want to investigate it. My client is Android application and server is apache 2.0 with php 5.
Thanks in advance.
CodeCaster allready gave part of the answer...
Just a really big tip here, php.net has a huge database with ALL of the functions and great examples that goes with them.
This is the main page about handling file uploads (just a table of contents) http://nl3.php.net/manual/en/features.file-upload.php
Here is pretty much everything you need to know:
http://nl3.php.net/manual/en/features.file-upload.post-method.php
W3Schools also has a tutorial on this.
http://w3schools.com/php/php_file_upload.asp

upload large files 100MB+ progress

I am having a lot of trouble handling large file uploading on the client side. I am looking for a way to show the progress of an upload while that person uploads. Then when it is finished, I need to have the file handled by a php script.
I am currently using http://code.google.com/p/swfupload/ SWFUPLOAD, but it is giving me trouble. It works 100% of the time for small files that are 5MB and so on, but for larger files that are over 100MB I am getting weird behavior. For example, when finished, the upload script does not receive some of the posted variables sometimes and so on. It seems to be breaking for reasons I cannot diagnose and I am quite frankly completely sick of it. (PS all my php settings are fine).
I am just looking for a simple solution for upload progress that does not have too many bells and whistles. I just want the ability to upload large files 100MB-500MB and then have the form posted to an upload script without the client side solution hanging or causing problems.
Has anyone worked on a project that required uploading large files and displaying progress? If so, what was your solution?
Did it involve flash?
Does anyone have any recommendations or a reliable solution?
Thanks in advance.
PHP have a restriction for upload files, you can modify this argument in PHP.ini, but if you can't have access to PHP.ini (some webhosting don't give access to PHP.ini) you can try upload file via FTP.
Can try with this (is in spanish) or with another good.

FTP-upload with PHP, print simple percentage?

hey guys,
i know there are a lot of "for-me-too-complicated" versions of progress-bars for php uploads out there.
however i have only a really basic knowledge of php and i have no idea how to implement this stuff.
i did a working file-upload script that transferres files from the user to my ftp-server. i'm using ftp_connect and ftp_put to do so.
i wonder how complicated it is to print a SIMPLE percentage value on to the page, to let the user know how far the upload has progressed.
i don't want any animated javascript stuff, just a simple percentage that shows the progress.
do you know a tutorial or something, or can you maybe give me a little explanation how i could do that. at least which methods return a progress value.
thank you in advance,matt
I know you said the flash uploaders are too complicated for you and you need a simple solution but the truth is there are none. If you could start your project over I would recommend using some known CMS with file upload support.
I think you should really give something like uploadify another chance. If you have problems with it ask here! There is a uploadify tag and really helpful peoples.
edit after your commenht: As seen on this page theres the idea to use uploadify to get the file to yoru server and then move it normally using ftp to your other space/server.
PHP/Apache talks to the client in a single request only. There is no simple way to actually have the client (know) how far the server is in the process. On uploads the file travels from the client to the server, so we generaly use Flash that can give us that information.
client (flash) -> server
What you are asking is something a bit fancier
client -> server -> ftp
And you want to know the progress between the server and the FTP. Mind you that even if you don't realize it the files are actually beeing transfered to the server and then from the server to the FTP server.
You will probably want to have the server update a database on given intervals with the progress so far and have the client AJAX the server to find out where the server is at.
You can also give socket.io a look!

Read file as its being uploaded

By default you cannot access a file that is uploaded until it has been fully transferred to the server.
What is the best way to get round this and be able to access the 'byte stream' as the file upload is in progress?
I think the closest you will get to this in PHP is looking at the various progress bar solutions that give you progress bars while doing file uploads to a PHP script. I don't know any of them in detail (I waited until SWFUpload became available to do this in Flash) but if you can get an upload's progress, it's likely you can get the data chunks themselves, too. (Update: the APC based solution can't. It seems to give the upload progress only.)
Check out this question, especially this answer and this one.
None of the approaches runs in pure vanilla PHP, they all need Perl or APC or other server-side stuff to work.
Final update: A cursory glance at the Raditha Mega Upload progress bar's Perl code makes me think this is your best bet, as it seems to be interacting with the actual file that is being uploaded. No guarantees, though.
You will need to have some kind of buffer where new data will be appended and where you read in chunks. Then check if there is new data and read that again.

Uploading a file to an external site with progress reporting

here is my situation:
I want to create an AJAX file-upload script, which will upload to an external site (ie: not the one the script is located in) and at the same time report the progress of the upload. How would I go about doing this? Note that the process must be secure.
If you are POSTing the file to another server there is no way to know the status of this upload since the upload is done between the users browser and the remote site.
If you have access to the script that handles file upload on the other site you could use Zend_File_Transfer and Zend_ProgressBar to fetch the information on the uplad progress from the other site and display it on your page.
Note: to use Zend_ProgressBar you need APC or uploadprogress extension.
There are two ways to do:
Using ajax and CGI
Using flash
The advantage of the flash method is that it does not require you to rewrite any server side scripts. This is especially good if you upload to a different server than yours. You do need to put a cross domain xml file on that server though.
The advantage of the ajax version is that it does not require your users to have flash installed.
There is no way to get the exact progress using ajax and php. Using php and ajax you can only know wheather the upload is in progress or finished. That is the reason why all ajax/php aplications have loading but no progress bar. If you explicitly want progress bar you should use a PERL CGI
Flash ( swfupload ) is probably the easiest. Vimeo.com uses swfupload to achieve this as well. Ihe only other method I know of involves php and APC which a tutorial of can be found at http://phpriot.com/articles/php-ajax-file-uploads.

Categories