Single picture upload is not complicated, here involves many pictures upload and the picture format of the check, to ensure that the upload must be pictures, to prevent uploading other files to the server.
The basic implementation algorithm is to use the form of an array, all the pictures are submitted to an array, the elements of the array to deal with each one.
The following are the referenced contents:
Picture Catalogue
$img _dir = ". /upload/";
... HTML display upload interface
/* Image upload processing * *
Upload pictures to the server
Initializing variables
$uploaded = 0;
$unuploaded = 0;
Only allow five pictures to upload
For ($i =0 $i <=5; $i + +)
{
Get information about the current picture
$is _file = $_files[' imgfile ' [' name '] [$i];
If the current picture is not empty
if (!empty ($is _file))
{
Store the information in the current picture in a variable
$result [$i] = "
". $_files[' imgfile ' [' name '] [$i]. "
". Round ($_files[' imgfile '] [' size '] [$i]/1024, 2]. " K
". $_files[' imgfile ' [' type '] [$i]. "
";
Determine if the type of uploaded picture is one of the jpg,gif,png,bmp and whether the upload succeeds
if (
$_files[' imgfile ' [' type '] [$i] = = "Image/pjpeg" | |
$_files[' imgfile ' [' type '] [$i] = = "Image/gif" | |
$_files[' imgfile ' [' type '] [$i] = = "Image/x-png" | |
$_files[' imgfile ' [' type '] [$i] = = "Image/bmp"
)
{
If the uploaded file does not exist on the server
if (!file_exists ($img _dir. $_files[' imgfile '] [' name '] [$i])
{
Transfer the picture file from the temporary folder to the directory we specified to upload
Move_uploaded_file ($_files[' imgfile '] [' tmp_name '] [$i],
$img _dir. $_files[' imgfile ' [' name '] [$i]];
$result [$i]. = "Success";
$uploaded + +;
}
else//If the file already exists on the server
{