StefanRSA Posted September 10, 2009 Share Posted September 10, 2009 My image upload, resize & rename script works fine for .jpg files. It sends the uploaded image names to the DB and save the files in a set folder. What should I do to my code to accept other image file type for images png, gif, tiff? My field script as follow: (This is to allow only 4 images to be uploaded) for($i=1;$i<=$pictot;$i++){ echo '<tr> <td>-</td><td>-</td><td>-</td><td>-</td><td>Image '.$i.'</td><td><input type="file" name="img'.$i.'"></td> </tr>'; } And then the upload script, after the form is submitted: $imgNumb=1; //This the "pointer" to images $DestinationDir="../ad_images/"; //Place the destination dir here $ThumbDir="../ad_images/thumb/"; //Place the thumb dir here do{ if($_FILES["img$imgNumb"][tmp_name]!=''){ $success++; $Unique=microtime(); // We want unique names, right? $destination=$DestinationDir.md5($Unique).".jpg"; $thumb=$ThumbDir.md5($Unique).".jpg"; $IMG=getimagesize($_FILES["img$imgNumb"][tmp_name]); $finalimage = resize($_FILES["img$imgNumb"][tmp_name], 600, $destination); //use the filename variable below to record the image name entered so that you can then use this variable to update your database if $filename = md5($Unique).".jpg"; $field = 'img'.$imgNumb; //mysql update your database fields $query = mysql_query("INSERT INTO ad_image (ad, user, image) VALUES ('$adnr', '$user', '$filename')") or die(mysql_error()); } $imgNumb++; } while($_FILES["img$imgNumb"][name]); if($success>=1){ echo $im1; echo $im2; echo $im3; echo $im4; //$message = "Images uploaded!"; //echo $message; } Quote Link to comment https://forums.phpfreaks.com/topic/173751-image-upload-to-allow-different-extentions-or-file-types/ Share on other sites More sharing options...
Adam Posted September 10, 2009 Share Posted September 10, 2009 First you need to check the file extension is allowed. There's plenty of methods both on here and Google if you do a quick bit of searching, they shouldn't be hard to implement. However you've hard-coded ".jpg" onto the end of your files, and I'll bet your resize() function doesn't cater for anything for other. The problem here being PHP use specific functions for different image formats whilst manipulating them, for example take a look at the imagejpeg function, and note the other functions in the 'see also' section. Post the content of the resize() function and should be able to help... Quote Link to comment https://forums.phpfreaks.com/topic/173751-image-upload-to-allow-different-extentions-or-file-types/#findComment-915959 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.