PHP multiple file and image upload examples, _php tutorial

Source: Internet
Author: User

PHP multiple file and image upload examples of detailed,


This article describes the PHP multiple files and image upload method. Share to everyone for your reference. The implementation method is as follows:

Multiple file upload is a single file upload based on the way to iterate through the array of the table singular group and then upload files to the server, the following to see a simple multiple file upload instance

Multiple file uploads and individual file uploads are handled the same way, with only a few input forms of type "file" in the client, and a different "name" attribute value specified. For example, in the following code, you can have the user select three local files to pass to the server together, and the client's form looks like this:

Copy the Code code as follows:
Multiple file Upload forms




In the preceding code, a form of three file types is organized as an array. When the above form teaches PHP script file mul_upload.php, the server side also uses global array $_files to store all of the above-mentioned files, but $_files is transformed from a two-dimensional array into a three-dimensional array, so that it can store multiple uploaded files of information. In the script file mul_upload.php, use the Print_r () function to output the contents of the $_files array, as shown in the following code:
Copy the Code code as follows: <?php
Print the contents of a three-dimensional array $_files, and look at the structure of the stored upload file
Print_r ($_files);
?>
When three local file submissions are selected, the output is as follows

Copy CodeThe code is as follows: Array (
[Myfile]=>array (
[Name]=>array (//$_files["myfile"] ["name"] stores the contents of all uploaded files
[0]=>rav.ini//$_files["myfile"] ["name"][0] The name of the first upload file
[1]=>msgsocm.log//$_files["myfile"] ["name"][1] The name of the second upload file
[2]=>notepad. EXE)//$_files["MyFile" ["Name"][2] The name of the third upload file
[Type]=>array (//$_files["myfile"] ["type"] stores the type of all uploaded files
[0]=>application/octet-stream//$_files["myfile"] ["type"][0] the first type of upload file
[1]=>application/octet-stream//$_files["myfile"] ["type"][1] the second type of upload file
[2]=>application/octet-stream]//$_files["myfile" ["type"][2] the type of the third upload file
[Tmp_name]=>array (
[0]=>c:/windows/temp/phpaf.tmp
[1]=>c:/windows/temp/phpb0.tmp
[2]=>c:/windows/temp/phpb1.tmp]
[Error]=>array (
[0]=>0
[1]=>0
[2]=>0]
[Size]=>array (
[0]=>64
[1]=>1350
[2]=>66560)]
)
By outputting the value of the $_files array, you can see that the upload of multiple files is the same as when uploading a single file, except that the $_files array has a slightly different structure. This way you can support a larger number of file uploads.
Examples are as follows:
Copy CodeThe code is as follows:



<title>Document upload</title>






Copy CodeThe code is as follows:



<title>Document upload</title>






Submit File Code
Copy CodeThe code is as follows:



<title>File Upload Results</title>


<?php
if ($_post["Submitfile"]!= "")
{
$Path = "./". Date (' Ym '). " /";
if (!is_dir ($Path))//create Path
{mkdir ($Path);}
echo "";
for ($i =0; $i
{//$_files["filelist"] ["size"] [$i] The order of arrangement can not be changed, because Fileist is a two-dimensional array
if ($_files["filelist" ["Size"] [$i]!=0)
{
$File = $Path. Date (' Ymdhm '). " _ ". $_files[" FileList "[" Name "] [$i];
if (Move_uploaded_file ($_files["FileList" ["Tmp_name"] [$i], $File))
{echo "File upload successful file type:". $_files["FileList" ["type"] [$i]. " "." File name: "
. $_files["FileList" ["Name"] [$i]. "
"; }
Else
{echo "filename:". $_files["FileList" ["Name"] [$i]. " Upload failed
"; }
}
}
echo "
Return ";
}
?>


The above example is based on JS to dynamically increase the upload file frame, so as to achieve the function of multi-file upload.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/909342.html www.bkjia.com true http://www.bkjia.com/PHPjc/909342.html techarticle php multiple file and image upload examples, this article describes the PHP multiple files and pictures upload method. Share to everyone for your reference. The implementation method is as follows: Multiple files ...

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