For PHP multi-image download and processing, it is difficult to write a piece of code for study.

Source: Internet
Author: User
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:

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.