Php multifile upload_php tutorial

Source: Internet
Author: User
Tags file upload script
Php multi-file upload. Php multi-file upload: using PHP to upload multiple files requires checking for many possible errors. How many fields can this script Upload? setting the maximum allowed file Upload allowed will be displayed in the HTML table. php multi-file Upload allowed
To upload multiple files using PHP, you need to check for many possible errors. This script allows you to upload the maximum allowed file size that will be displayed in the HTML table. The php. ini file also contains a default value of 2 MB or 2 MB for upload_max_filesize in The ini option. This value also takes into account the error during the check.

These errors are information stored in the array and require that each file be uploaded based on the information generated or uploaded successfully. The form itself is verification, according to the W3C validators in DOCTYPE.


/*
*
* @ Multiple File upload script.
*
* @ Can do any number of file uploads
* @ Just set the variables below and away you go
*
* @ Author: Kevin Waterson
*
* @ Copywrite 2008 PHPRO. ORG
*
*/

Error_reporting (E_ALL );

/*** The upload directory ***/
$ Upload_dir = './uploads ';

/*** Numver of files to upload ***/
$ Num_uploads = 5;

/*** Maximum filesize allowed in bytes ***/
$ Max_file_size = 51200;

/*** The maximum filesize from php. ini ***/
$ Ini_max = str_replace ('M', '', ini_get ('upload _ max_filesize '));
$ Upload_max = $ ini_max * 1024;

/*** A message for users ***/
$ Msg = 'Please select files for uploading ';

/*** An array to hold messages ***/
$ Messages = array ();

/*** Check if a file has been submitted ***/
If (isset ($ _ FILES ['userfile'] ['tmp _ name'])
{
/** Loop through the array of files ***/
For ($ I = 0; $ I <count ($ _ FILES ['userfile'] ['tmp _ name']); $ I ++)
{
// Check if there is a file in the array
If (! Is_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'] [$ I])
{
$ Messages [] = 'No file uploaded ';
}
/*** Check if the file is less then the max php. ini size ***/
Elseif ($ _ FILES ['userfile'] ['size'] [$ I]> $ upload_max)
{
$ Messages [] = "File size exceeds $ upload_max php. ini limit ";
}
// Check the file is less than the maximum file size
Elseif ($ _ FILES ['userfile'] ['size'] [$ I]> $ max_file_size)
{
$ Messages [] = "File size exceeds $ max_file_size limit ";
}
Else
{
// Copy the file to the specified dir
If (@ copy ($ _ FILES ['userfile'] ['tmp _ name'] [$ I], $ upload_dir. '/'. $ _ FILES ['userfile'] ['name'] [$ I])
{
/*** Give praise and thanks to the php gods ***/
$ Messages [] = $ _ FILES ['userfile'] ['name'] [$ I]. 'uploaded ';
}
Else
{
/*** An error message ***/
$ Messages [] = 'uploading'. $ _ FILES ['userfile'] ['name'] [$ I]. 'failed ';
}
}
}
}
?>
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>


Multiple File Upload





If (sizeof ($ messages )! = 0)
{
Foreach ($ messages as $ err)
{
Echo $ err .'
';
}
}
?>




Http://www.bkjia.com/PHPjc/444986.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444986.htmlTechArticlephp multi-file upload using PHP to upload multiple files requires many possible error checks. How many fields can this script Upload? setting the maximum allowable file size displayed in the HTML table...

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.