Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML File Upload - why use IFrame

I have been trying to get file uploads working in IE8. To only solution I have seen is posting to an IFrame. Why is this done? Is it not possible to have a simple form e.g.

<form action="test.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

Which submits directly to PHP

if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}

Why would an IFrame be needed?

Thanks

like image 812
katie hudson Avatar asked Nov 16 '15 10:11

katie hudson


1 Answers

You don't need an iframe to upload a file.

You need an iframe to upload a file without leaving the current page (i.e. for Ajax). Modern browsers support FormData which allows you to upload files with XMLHttpRequest.

like image 199
Quentin Avatar answered Oct 02 '22 03:10

Quentin