One of the most original and simplest examples of IFRAME upload:
The foreground uploads the page index.html, mainly is a form and a JS callback function. When uploading a file, the form's method, Enctype property must be the same as the following code. The target value is then set to the name of the IFRAME, so that no refresh upload file can be implemented.
| The code is as follows |
Copy Code |
|
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Upload file </title>
<body>
<script>
function Callbackfunction (str) {
Alert ("Upload succeeded");
}
</script>
<form action= "uploadfile.php" enctype= "Multipart/form-data" method= "post" target= "Iframeupload" >
<iframe name= "Iframeupload" "src=" "width=" "Height= frameborder=0" "No." Scrolling= "no" style= "Display:none" > </iframe>
<input id= "Test_file" name= "Test_file" type= "File" >
<input value= "Upload file" type= "Submit" >
</form>
</body>
|
Background upload processing page uploadfile.php, this code for the simple upload code, no error and exception handling. Upload code after completion, to tell the parent page has been uploaded, so, in this page call the parent page callback function callbackfunction, this function can have parameters, form their own definition.
| The code is as follows |
Copy Code |
|
<?php
Set_time_limit (0);
if ($_server[' Request_method ']== ' POST ') {
Move_uploaded_file ($_files["Test_file"] ["Tmp_name"],
DirName ($_server[' script_filename '). " /uploadtemp/". $_files["Test_file" ["name"]);
echo "<script>window.parent.callbackfunction ();</script>";
}
?> |
The above is to use an IFRAME without refreshing upload files of the simple method, want to be robust program words need to be refined