iframe based photo/file uploader
Posted by mahmud ahsan on July 21, 2009
Facebook, Java Script, PHP
suppose your client tell you to create a form where he needs file/photo uploader that will work instantly when you will select file/photo.
recently i’ve faced same type of situation for one of facebook app and here is the solution i developed for my purpose.
<form name="fuser" action="http://temp.com/fsubmit.php" method="POST"> <iframe src="photo.php" style="margin-left:-10px;" frameborder="0" scrolling="no" width="465" height="70"></iframe> </form>
in facebook app, i’ve to use
<fb:iframe></fb:iframe>
not
<iframe></iframe>
in iframe src=”" i’ve specified photo.php and below is the code for photo.php
<?php
if ($_FILES['photo']['error'] == UPLOAD_ERR_OK && !empty($_FILES['photo']['tmp_name'])) {
//here i've to upload file into amazon s3 and i set $fileUrl = true;
//you can upload file in local filesystem that code you have to write in this place
$fileUrl = true;
}
?>
<script type="text/javascript">
function photoUpload(){
var obj = document.getElementById('fphoto');
obj.submit();
}
</script>
<?php if (isset($fileUrl) && !empty($fileUrl)) { ?>
Photo uploaded successfully!
<?php } else { ?>
<form action="photo.php" id="fphoto" method="POST" enctype="multipart/form-data">
<input type="file" name="photo" size="56" onchange="photoUpload();">
</form>
<?php } ?>
now when user will select any file, the from will submit by javascript inside iframe, so the main page will not reload and user will instantly see the success message.
Related Posts
Comments (5)








Dear Mahmud,
Your iframe based photo/file uploader is just what i am looking for on Facebook! And i can really use some more help on this.
Would you like to assist me further? And is this uploader still online on Facebook somewhere?
Best regards,
Rogier
you’re welcome and this uploader is still online on facebook.
Hi Mahmud,
Where is the uploader on Facebook for us to take it for a test run.
Best regards,
Rogier
great mahmud!!
I just use this in an admin panel, where multiple image has to upload without page reloading. I searched and found many Ajax, Flash based , but yours one is shortest and easy
@Saif, You’re welcome.