Simple PHP multi-graph Upload of small program code

Source: Internet
Author: User
I have also written many Image upload programs before, but none of them are short below. The simpler the program, the better, right? First, run the source code. you can copy it to your computer to run it ~

The code is as follows:





Multi-file Upload



// Upload file information
$ Img = $ _ FILES ['IMG '];
If ($ img)
{
// File storage directory, which is the same as the php file
$ Dir = dirname (_ file __);
$ I = 0;
Foreach ($ img ['tmp _ name'] as $ value)
{
$ Filename = $ img ['name'] [$ I];
If ($ value)
{
$ Savepath = "$ dir \ $ filename ";
$ State = move_uploaded_file ($ value, $ savepath );
// If the upload is successful, preview
If ($ state)
{
Echo "";
}
}
$ I ++;
}
}
?>



Move_uploaded_file () function
The move_uploaded_file () function moves the uploaded file to the new location. If yes, true is returned. otherwise, false is returned.
Usage: move_uploaded_file (file, newloc)
Parameter file, required. Specifies the file to be moved.
Required. Specifies the new location of the file.
This function checks and ensures that the file specified by the file is a valid file to be uploaded (that is, the file is uploaded through the http post Upload mechanism of PHP ). If the file is valid, it is moved to the file specified by newloc.
If the file is not a valid Upload file, no operation is performed. move_uploaded_file () returns false.
If the file is valid but cannot be moved for some reason, no operation will occur. move_uploaded_file () will return false, and a warning will be issued.
This check is especially important. if the uploaded file may display the content to the user or other users in the system.
Note: This function is only used for files uploaded through http post.
Note: If the target file already exists, it will be overwritten.

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.