For PHP multi-image upload and processing, it is difficult to write a piece of code for study as follows: a product name contains four pictures. Upload the image to the "upimg" folder in the current path, and save the image path to the corresponding mysql field. & Nbsp; therefore, when filling in product information, you must Upload four images for the same product name. & Nbsp; --------- Number of PHP multi-graph uploads and processing, which makes it difficult to write a code segment for study.
The requirements are as follows:
A product name contains four images. Upload the image to the "upimg" folder in the current path, and save the image path to the corresponding mysql field.
Therefore, when filling in product information, you must Upload four images for the same product name.
--------- Database structure:
Database name: Atest,
Table name: prodcut,
Fields corresponding to the table: pname, pic1, pic2, pic3, pic4... (all char types)
-------- I designed the HTML form as follows:
HTML code
Notes:
1. in the database, a product name + four Image paths form a data record, instead of storing multiple data records.
2. you must rename the image file; otherwise, duplicate images may occur;
3. before uploading a file, check whether the image format is jpg, bmp, gif, or png. otherwise, do not upload the image;
4. the size of the uploaded image cannot exceed 2 MB; that is, name = "MAX_FILE_SIZE" value = "2000000"
Please add another code: upload. php. thank you!
------ Solution --------------------
I solve this problem:
After a successful Upload, rename the uploaded class, use one class for an image, and use four classes for four files ..... Successfully Implemented
I am the most stupid method. ......
Upload a single image: uploadclass. php)
PHP code
Return and try again? Click me "; exit;} else {$ filename = explode (". ", $ _ FILES ['Pic '] ['name']); // same as above, the pic must be renamed do {$ filename [0] = random (10 ); // rename $ name = implode (". ", $ filename); // $ name1 = $ name. ". mcncc "; $ uploadfile = $ uploaddir. $ name; // This $ uploadfile is the image path of the corresponding field of the database to be inserted, which must be changed accordingly} while (file_exists ($ uploadfile )); // the function name must correspond to the most changed if (move_uploaded_file ($ _ FILES ['Pic '] ['tmp _ name'], $ uploadfile )) // PIC needs to correspond to the most changed {if (is_uploaded_file ($ _ FILES ['Pic '] ['tmp _ name']) // the pic must be changed accordingly. {echo "the Images Upload failed! ";} Else {echo"
Your file has been uploaded:
"; // Src = corresponds to the latest echo"
Continue to upload
";}}?>
------ Solution --------------------
One test example
PHP code
File 1: