PHP multi-image Upload value

Source: Internet
Author: User
PHP multi-image Upload has a multi-image upload problem. Three image upload functions are specified in the INPUT file. after you have done this, you will find that the upload is successful and you can change the name automatically, and 3 cannot be renamed automatically. how can I change the name?

$ Uploaddir = "uploadfiles/"; // Set the file storage directory to include/$ type = array ("jpg", "gif", "bmp", "jpeg ", "png"); // set the type of the file to be uploaded $ patch = "uploadfiles/"; // path of the program // Obtain the file extension function fileext ($ filename) {return substr (strrchr ($ filename ,'. '), 1);} // Obtain the file extension function fileext2 ($ filename2) {return substr (strrchr ($ filename2 ,'. '), 1);} // get the file extension function fileext3 ($ filename3) {return substr (strrchr ($ filename3 ,'. '), 1 );} // Function random ($ length) {$ hash = 'Java-'; $ chars = 'callback'; $ max = strlen ($ chars)-1; mt_srand (double) microtime () * 1000000); for ($ I = 0; $ I <$ length; $ I ++) {$ hash. = $ chars [mt_rand (0, $ max)];} return $ hash ;} $ a = strtolower (fileext ($ _ FILES ['img1'] ['name']); $ B = strtolower (fileext2 ($ _ FILES ['img2'] ['name']); $ c = strtolower (f Ileext3 ($ _ FILES ['img3'] ['name']); // you can determine the file type if (! In_array (strtolower (fileext ($ _ FILES ['img1'] ['name']), $ type) {$ text = implode (",", $ type ); echo "you can only upload the following types of files:", $ text ,"
";}// Generate the target file named else {$ filename = explode (". ", $ _ FILES ['img1'] ['name']); $ filename2 = explode (". ", $ _ FILES ['img2'] ['name']); $ filename3 = explode (". ", $ _ FILES ['img3'] ['name']); do {$ filename [0] = random (10 ); // set the length of the random number $ name = implode (". ", $ filename); // $ name1 = $ name. ". mcncc "; $ uploadfile = $ uploaddir. $ name; $ filename [1] = random (10); // Set the random number length $ name2 = implode (". ", $ filename2); // $ name1 = $ name. ". mcncc "; $ uploadfile2 = $ uploaddir. $ name2; $ filename [2] = random (10); // Set the random number length $ name3 = implode (". ", $ filename3); // $ name1 = $ name. ". mcncc "; $ uploadfile3 = $ uploaddir. $ name3;} while (file_exists ($ uploadfile); if (move_uploaded_file ($ _ FILES ['img1'] ['tmp _ name'], $ uploadfile )) {// if (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {// preview the output image // echo" You have uploaded the file and uploaded the image to preview it:
"; // Echo"
Continue Upload "; //} // Else {// echo" Upload failed! ";} If (move_uploaded_file ($ _ FILES ['img2'] ['tmp _ name'], $ uploadfile2 )) {// if (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {// preview the output image // echo" You have uploaded the file and uploaded the image to preview it:
"; // Echo"
Continue Upload "; //} // Else {// echo" Upload failed! ";} If (move_uploaded_file ($ _ FILES ['img3'] ['tmp _ name'], $ uploadfile3 )) {// if (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {// preview the output image // echo" You have uploaded the file and uploaded the image to preview it:
"; // Echo"
Continue Upload "; //} // Else {// echo" Upload failed! ";}}$ SourceFileName = $ uploadfile; $ SourceFileName2 = $ uploadfile2; $ SourceFileName3 = $ uploadfile3;


Reply to discussion (solution)

?? Yes ??, No ?? Yes $ filename [0], $ filename [1], $ filename [2]; and ?? Yes $ filename [0], $ filename2 [0], $ filename3 [0]

Do {$ filename [0] = random (10); // Set the random number length $ name = implode (". ", $ filename); // $ name1 = $ name. ". mcncc "; $ uploadfile = $ uploaddir. $ name; $ filename [1] = random (10); // Set the random number length $ name2 = implode (". ", $ filename2); // $ name1 = $ name. ". mcncc "; $ uploadfile2 = $ uploaddir. $ name2; $ filename [2] = random (10); // Set the random number length $ name3 = implode (". ", $ filename3); // $ name1 = $ name. ". mcncc "; $ uploadfile3 = $ uploaddir. $ name3 ;}


Modified Program
 ";}// Generate the target file named else {$ filename = explode (". ", $ _ FILES ['img1'] ['name']); $ filename2 = explode (". ", $ _ FILES ['img2'] ['name']); $ filename3 = explode (". ", $ _ FILES ['img3'] ['name']); do {$ filename [0] = random (10 ); // set the length of the random number $ name = implode (". ", $ filename); // $ name1 = $ name. ". mcncc "; $ uploadfile = $ uploaddir. $ name; $ filename2 [0] = random (10); // Set the random number length $ name2 = implode (". ", $ filename2); // $ name1 = $ name. ". mcncc "; $ uploadfile2 = $ uploaddir. $ name2; $ filename3 [0] = random (10); // Set the random number length $ name3 = implode (". ", $ filename3); // $ name1 = $ name. ". mcncc "; $ uploadfile3 = $ uploaddir. $ name3;} while (file_exists ($ uploadfile); if (move_uploaded_file ($ _ FILES ['img1'] ['tmp _ name'], $ uploadfile )) {// if (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {// preview the output image // echo"
 
  
You have uploaded the file and uploaded the image to preview it:
 
"; // Echo"
Continue Upload "; //} // Else {// echo" Upload failed! ";} If (move_uploaded_file ($ _ FILES ['img2'] ['tmp _ name'], $ uploadfile2 )) {// if (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {// preview the output image // echo" You have uploaded the file and uploaded the image to preview it:
"; // Echo"
Continue Upload "; //} // Else {// echo" Upload failed! ";} If (move_uploaded_file ($ _ FILES ['img3'] ['tmp _ name'], $ uploadfile3 )) {// if (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name']) {// preview the output image // echo" You have uploaded the file and uploaded the image to preview it:
"; // Echo"
Continue Upload "; //} // Else {// echo" Upload failed! ";}}$ SourceFileName = $ uploadfile; $ SourceFileName2 = $ uploadfile2; $ SourceFileName3 = $ uploadfile3;?>



It turns out that there is an error. thank you!

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.