A php program code without refreshing file Upload _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
A php program code for refreshing file upload. 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 of these methods can achieve resumable Upload of new files. We use the iframe framework to upload files, and ajax to upload files, 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:





Upload files



Script
Function CallbackFunction (str ){
Alert ("uploaded successfully ");
}
Script


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:

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.