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.
...