Uploading a single image is not complex. this involves uploading multiple images and verifying the image format. This ensures that the uploaded images are always used to prevent uploading other files to the server. The basic implementation algorithm uses an array to submit all images to an array and process the elements of the array one by one .? Php/************************** "> <LINKhref =" http: // w
Uploading a single image is not complex. this involves uploading multiple images and verifying the image format. This ensures that the uploaded images are always used to prevent uploading other files to the server.
The basic implementation algorithm uses arrays to submit an array of all images and process the elements of the array one by one.
/*************************************** ******
* File: uploadimg. php
* Purpose: upload an image program
* Version: v1.0
* Created:
* Modification:
* Copyright: heiyeluren
**************************************** *****/
// Image directory
$ Img_dir = "../upload /";
//...... Html display Upload interface
/* Image Upload processing */
// Upload the image to the server
// Initialize the variable
$ Uploaded = 0;
$ Unuploaded = 0;
// Only five images can be uploaded
For ($ I = 0; $ I <= 5; $ I ++)
{
// Obtain the information of the current image
$ Is_file = $ _ FILES ['imgfile'] ['name'] [$ I];
// If the current image is not empty
If (! Empty ($ is_file ))
{
// Store the information of the current image in the variable
$ Result [$ I] ="
". $ _ FILES ['imgfile'] ['name'] [$ I]."
". Round ($ _ FILES ['imgfile'] ['size'] [$ I]/1024, 2)." K
". $ _ FILES ['imgfile'] ['type'] [$ I]."
";
// Determine whether the type of the uploaded image is jpg, gif, png, or bmp, and whether the upload is successful.
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 image file from the temporary folder to the directory we specified for Upload
Move_uploaded_file ($ _ FILES ['imgfile'] ['tmp _ name'] [$ I],
$ Img_dir. $ _ FILES ['imgfile'] ['name'] [$ I]);
$ Result [$ I]. = "successful ";
$ Uploaded ++;
}
Else // if the file already exists on the server
{
$ Result [$ I]. = "the file already exists ";
$ Unuploaded ++;
Continue;
}
}
Else
{
$ Result [$ I]. = "failed ";
$ Unuploaded ++;
}
$ Result [$ I]. ="";
} // End if
} // End
// If no image is selected
If (empty ($ result ))
{
Prompt_msg ("error message", "No image is selected. "," Back to the previous step "," uploadimg. php? Action = upload ");
Exit ();
}
// Display all uploaded results
Echo"
Foreach ($ result as $ value)
{
Echo $ value;
}
Echo"
File name |
Size |
Type |
Upload result |
";
Upload ". ($ uploaded + $ unuploaded).", successful: $ uploaded, failed: $ unuploaded |
[Continue uploading] [browsing Images] |
";