A php no refresh upload file program code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.