Php asynchronous image upload methods. There are two commonly used methods for asynchronous image upload. one is to use iframe and the other is to use ajax to implement third-party plug-ins. There are two common methods to upload an image form to submit a target to achieve asynchronous image upload. one is to use iframe, and the other is to use ajax to implement third-party plug-ins.
Upload the image form and submit the target to a hidden iframe,
| The code is as follows: |
|
|
Form action = "upload. php" id = "form1" name = "form1" enctype = "multipart/form-data" method = "post" target = "uploadIframe">
|
Then, the background processes the uploaded image logic and returns it to the foreground. you can use ajax to modify the DOM object of the current page to implement the friendly function of refreshing the uploaded image.
Instance
| The code is as follows: |
|
|
A.html
|
PHP code:
| The code is as follows: |
|
If ($ _ FILES ["test_file"] ["error"]> 0)
{
Echo "Error:". $ _ FILES ["test_file"] ["error"]."
";
}
Else
{
// The method used to determine the image attributes will not be written here. Expand it by yourself.
$ Filetype = strrchr ($ _ FILES ["test_file"] ["name"], ".");
$ Filetype = substr ($ filetype, 1, strlen ($ filetype ));
$ Filename = "img/". time ("YmdHis"). ".". $ filetype;
Move_uploaded_file ($ _ FILES ["test_file"] ["tmp_name"], $ filename );
Echo' |