About PHP Multi-image down and processing, trouble master write a piece of code for study

Source: Internet
Author: User
About PHP upload and processing of multi-image, Trouble master to write a piece of code for learning
The requirements are as follows:
There are 4 pictures under a product name. The image is uploaded to the "upimg" folder in the current path, and the picture path is stored in the MySQL corresponding field.
So when I do product information filling in, for the same product name, you must upload 4 images.

---------Database structure:
Database name: atest,
Table name: Prodcut,
Table corresponding to the field: Pname,pic1,pic2,pic3,pic4 ... (All char types)

--------HTML Form I designed this:
HTML Code
  
   


A few things to note:
1, in the database, a product name + four image path to form a piece of data, rather than save as multiple data.
2, the image file must be renamed, or there will be duplicates;
3, before uploading the file to detect whether the image format is jpg,bmp,gif or PNG, otherwise do not upload;
4, the volume of the uploaded image can not exceed 2M; that is: Name= "max_file_size" value= "2000000"

Trouble to add a section of code: upload.php, thank you!

------Solution--------------------
That's how I solved it:
After a successful, upload the class rename, a picture with a class, 4 files in four classes ..... Successful implementation of
This is the stupidest way I've been. And so the master out of the method with the array loop implementation ...



Single image upload class: uploadclass.php (corresponding to multi-image upload, rename it, and the code snippet in the corresponding changes, can be multiple references, multiple uploads)

PHP Code
  Return and try Again?click me "; exit;} else{$filename =explode (".", $_files[' pic ' [' name ']);//Ibid., Pic needs to be renamed do{$filename [0]=random (10);//When using the function random, The same should correspond to renaming $name=implode (".", $filename);//$name 1= $name. " MCNCC "; $uploadfile = $uploaddir. $name;//This $uploadfile is the picture path you want to insert into the database corresponding fields, need to change}while (file_exists ($uploadfile)) ///The function name needs to correspond to the most changed if (Move_uploaded_file ($_files[' pic '] [' tmp_name '], $uploadfile))//pic need to correspond to the most changed {if (Is_uploaded_file ($_ files[' pic ' [' tmp_name ']))//pic need to correspond to make changes {echo "the Images Upload failed!";} Else{echo "
  
   
    Your file has been uploaded:
   
  
"//src=" is the most changed echo.
Continue to upload ";}}}? >
------Solution--------------------
A test example
PHP code
 
      
      
Files 1:
  • Related Article

    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.