Showing posts with label file upload. Show all posts
Showing posts with label file upload. Show all posts

Wednesday, February 23, 2011

Image upload without page refresh

If you are uploading a file without refreshing a page, you do not need any ajax or any flash uploader for such a realtime uploader. This can be easily achieved by simple conventional HTML and javascript. The solution is too simple to believe it exist. The idea is to use a iframe and redirect the upload destination page to the iframe instead of the current page.

This is achieved by the "target" attribute. You can use this attribute to plain hyperlinks as well. For example if you have <a href="mypage.html" target="iframe_1">Click</a> and you have a iframe whose id is "iframe_1", then the page mypage.html will open in the iframe instead of the current page. So the same concept applies for file upload without refreshing current page.

You need to have 2 php files, let the first file be, "upload.php" with the following: