clanstyles Posted June 29, 2007 Share Posted June 29, 2007 I have: if ($_FILES['image']['type'] == "image/gif" || $_FILES['image']['type'] == "image/jpg" || $_FILES['image']['type'] == "image/jpeg") { $ran[0] = rand(1, 9999); $ran[1] = rand(1, 9999); if(isset($_REQUEST['image']) == 0) { copy ($_FILES['image']['tmp_name'], "uploadedimages/".$ran[0].$ran[1].$_FILES['image']['name']) or die ("Could not upload image #1."); } if(isset($_REQUEST['image']) == 1) { copy ($_FILES['image']['tmp_name'], "uploadedimages/".$ran[0].$ran[1].$_FILES['image']['name']) or die ("Could not upload image #1."); } if(isset($_REQUEST['image']) == 2) { copy ($_FILES['image']['tmp_name'], "uploadedimages/".$ran[0].$ran[1].$_FILES['image']['name']) or die ("Could not upload image #1."); } echo count($_REQUEST['image']); echo $_REQUEST['image']; $str = implode("|", $_REQUEST['image']); echo $str; I'm trying to upload 3 image and then implde them in | style. Later I can expode it and shhow them blah have that done easy. This is hard for me. Ican't use foreach statements. Thanks Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 Bump if this helps, its not for an image uploading site. Its for like post a pic of ur house so we can see it t ype of thing:D Nothing bad.. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 First whats the issue, secondly what is all the if(isset($_REQUEST['image']) == 1) for? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 Well I have <input type="file" name="image[]"> 3 times ( 3 differnet inputs for images and want to upload all 3 take the names and implode w/ | between. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 What? 3 forms? you can't name a form with a array case and expect it to work you have to use a static array system. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 I'm nwe to this stuff please do explain Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 your method's seem wack. This is my script for uploading X images. I also included the form <html> <form name='FORMNAME' action='ACTION' method='post' enctype='multipart/form-data'> <input type='hidden' name='newimages' value='yes' /> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <br/> <input type="file" name="imagefile0"/><br/> <input type="file" name="imagefile1"/><br/> <input type="file" name="imagefile2"/><br/> <input type="file" name="imagefile3"/><br/> //Append to the inputs for the number of images you need. </html> This is the part of the process page that handles these images <?php //Lets add some nubmers for safety $random_digit = $_POST['random']; (can be loaded here, but I have the option to reupload images so this way they don't use new numbers $us = "_"; $pathto = "/files/".$random_digit.$us; //stores the image in the folder files/randomnumber_ $i = 0; while ($i <= 3) //Handles 4 images selfexplainotory { if ($_FILES['imagefile'.$i]['type'] == "image/jpeg" || $_FILES['imagefile'.$i]['type'] == "image/jpg" || $_FILES['imagefile'.$i]['type'] == "image/pjpeg" || $_FILES['imagefile'.$i]['type'] == "image/pjpg"){ $count++; $file_name = ""; $file_name .= "temp."; $file_name .= str_replace(".jpg","",str_replace("/","",str_replace("image","",$_FILES['imagefile'.$i]['type']))); //Replaces to lowercase only .jpg files $ext = ".jpg"; //Lets make a new name $new_file_name=$random_digit.$us.$count.$ext; //Lets Path it $path[$count]= "files/".$new_file_name; if(copy($_FILES['imagefile'.$i]['tmp_name'], $path[$count])){ echo "It Copied!!!<br/>"; } else{ echo "copy Failed<br/>"; } } $i++; } ?> Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 not working It can't get past the iamge type.. while ($i < 3) //Handles 4 images selfexplainotory { if ($_FILES['image'.$i]['type'] == "image/jpeg" || $_FILES['image'.$i]['type'] == "image/jpg" || $_FILES['image'.$i]['type'] == "image/pjpeg" || $_FILES['image'.$i]['type'] == "image/pjpg"){ $count++; $file_name = ""; $file_name .= "temp."; $file_name .= str_replace(".jpg","",str_replace("/","",str_replace("image","",$_FILES['imagefile'.$i]['type']))); //Replaces to lowercase only .jpg files $ext = ".jpg"; //Lets make a new name $new_file_name=$random_digit.$us.$count.$ext; //Lets Path it $path[$count]= "uploadedimages/".$new_file_name; if(copy($_FILES['imagefile'.$i]['tmp_name'], $path[$count])){ echo "It Copied!!!<br/>"; } else{ echo "copy Failed<br/>"; } } else { echo "You have a bad image type."; } echo " <td ><label>(Optinal) Image #1:</label></td>"; echo " <td ><input type=\"file\" name=\"image1\"></td>"; echo " </tr>"; echo " <tr>"; echo " <td ><label>(Optinal) Image #2:</label></td>"; echo " <td ><input type=\"file\" name=\"image2\"></td>"; echo " </tr>"; echo " <tr>"; echo " <td ><label>(Optinal) Image #3:</label></td>"; echo " <td ><input type=\"file\" name=\"image3\"></td>"; echo " </tr>"; echo " <tr>"; Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 are you uploading jpgegs? did u make a folder called files with proper chmod? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 I'm uploading a jpg file ( En-Us_techlogo.jpg ). the folder is /uploadimages/ and ive uploaded to it already so I kno wit works Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 that doesn't sound clear. It worked with one. But I need it to work with three they are called image1 image2 and image3 ( the Fields ). Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 your issue is because your numbers in the field names (not form name as you said earlier) are starting at 1 not 0 start it at 0 its failing because image0 erroring internally probably Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 nope not it.. $i=1; while ($i < 4) //Handles 4 images selfexplainotory and still Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 your form is a multi type data right? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 yeah Quote Link to comment Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 i guess u need to create a function then call that upload function in the loop sample function upload(filetobe uploade tempname, filename , ect) { } then create a loop while() { upload(filetobe uploade tempname, filename , ect) } hope that helps Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 since its a logical error try using echoes in certain parts to pinpoint where it fails. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 okay i fixed it i got it going to the copy part, now the problem is copy Failed :-/ Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 do you have the folder they are going into made? also is that folder allowing all users to write to it chmod(777) I think is it Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 Well it worked earliier. :-/ But i need it to support like gif and png and jpg file types not just jpg thats why i had a random number put infront so its really unlikely that there would ever be two file names as the same i added image/gif to the list. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 8 digit random is sufficent , but it should be working make sure the folder is all right. Secondly you should develop your own naming system so that its in a format of your liking (and handles all extensions) should make it all lowercase anyway which is easier to do than what I did. This is only code I just haven't updated in a year or so Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 Also, I need all the files to implode with a | between each name so i can store t hem then explode later . Thanks ... I hate these t hings. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 no need my system was naming them temp_$randomnumber_$imgnumber.$extension so you can recall them from $randomnumber I don't even understand that sentence implode with a | between each name. You are naming each file individually not together so why you need that? Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 29, 2007 Author Share Posted June 29, 2007 for storage. See I have one feild called image. I want to implode it like haah.gif|peter.jpg|grandma.gif . Then alter just have to go $vars = explode("|", $result['image']) Then go and easily just point to the images. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 29, 2007 Share Posted June 29, 2007 for dynamic image naming thats a bad idea. If you images are associated with mysql data don't use random numbers but instead the mysql ID number for them and then array inside like mysqlID_ImgnumberX.extension Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.