Php asynchronous image upload methods-PHP Tutorial

Source: Internet
Author: User
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'

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.