A PHP program code for refreshing file uploads

Source: Internet
Author: User

To upload a non-refreshing file, we use the iframe framework to upload the file. The other is to use ajax to upload the file, both methods can enable the upload function of the brushless newest file.

A simple iframe upload example:

The front page index.html is mainly a form and a js callback function. When uploading a file, the method and enctype attributes of the form must be the same as the following code. Set the target value to the name of iframe, so that you can upload files without any need.

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">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> upload a file </title>
</Head>

<Body>
<Script>
Function CallbackFunction (str ){
Alert ("uploaded successfully ");
}
</Script>
<Form action = "uploadfile. php" enctype = "multipart/form-data" method = "post" target = "iframeUpload">
<Iframe name = "iframeUpload" src = "" width = "350" height = "35" frameborder = 0 SCROLLING = "no" style = "display: NONE "> </iframe>
<Input id = "test_file" name = "test_file" type = "file">
<Input value = "Upload File" type = "submit">
</Form>
</Body>
</Html>

Uploadfile. php on the background upload processing page. This code is a simple upload code without error and exception handling. After the upload code is executed, you need to tell the parent page that the upload has been completed. Therefore, you can call the callback function CallbackFunction of the parent page on this page. This function can be defined as a parameter.

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 a simple method to use iframe to implement the upload of files without any need. If you want a robust program, you need to refine it.

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.