As web technology evolves, a focus has always been on trying to make a web application act more like a desktop application. This involves the implementations of techniques like AJAX and DOM to make web pages act more swift and sound. In this article we’ll talk about ways to improve the file uploading experience with PHP.
Traditionally, while uploading files, you specify the file path in a ‘HTML file input’ field. The file is uploaded to the server when submitting the form.
There are two problems with this method:
- Submitting the form refreshes the page, or loads another page.
- While uploading BIG files there is no indicator to show the data transfer progress.
There aren’t many remedies to solve this problem.
Here is the list of things that we can’t do:
- Uploading files with AJAX.
This is because JavaScript has no access to local files. - Report the progress while a file is being uploaded. This is a problem, that only exists with PHP.
Clearing out doubts:
- Can I submit a HTML form using AJAX with POST method?
Yes, it is possible. What’s not possible is to submit a file using AJAX.
Alternative ways:
An alternative to AJAX to prevent page reloading is to use inline frames. An inline frame can load one HTML files within another. So if you put your form inside an inline frame, submitting the form won’t reload the whole page.
What about a progress bar or an indicator for uploading progress?
To tell you the truth, it is impossible. It can’t be done using PHP alone.
PHP uses a function, ‘move_uploaded_file’ to move the already uploaded files to destination directory on the server. The files are initially uploaded to a temporary directory and there is no way to access that file while the uploading is in progress.
Any alternative to that?
- You can use a BIT of help from other PHP like languages like Perl or Java, just for uploading process. But, for that, you need to have them installed at the first place of course.
- You can also modify PHP itself, to provide a way to access the properties of the temporary file it uses while the uploading is in progress. But its almost impossible on shared hosting environment.
- You can use client sided component like Java applet or a flash object to upload the files in a much more controlled way. But I think you are better off without it, for small files.
Can I get CODE for the iframe technique?
Not now, you can either search for it on google, or comment on this post to have me write a code for that.









Hey guru,
I think we can have coilation to make a site
its download site, like filehippo.com and i need it better than that site. If you’d like to help me, plz contact me on the mail I provided above 