stevesimo Posted May 8, 2007 Share Posted May 8, 2007 Hi, I am attempting to use some code I found in an article on this site to upload an image to the server. I have got this working although I need to be able to restrict the image formats to GIF, JPG and PNG. I have got it working where it will upload a GIF but not a PNG or JPG. Anyone know how I fix this? Here is my code: if(isset( $Submit )) { if ($_FILES['imagefile']['type'] == "image/gif" OR $_FILES['imagefile']['type'] == "image/png" OR $_FILES['imagefile']['type'] == "image/jpg"){ copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) or die ("Could not copy"); echo ""; echo "Name: ".$_FILES['imagefile']['name'].""; echo "Size: ".$_FILES['imagefile']['size'].""; echo "Type: ".$_FILES['imagefile']['type'].""; echo "Copy Done...."; }else{ echo "<br><br>"; echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; } } Thanks Steve Quote Link to comment https://forums.phpfreaks.com/topic/50499-solved-restricting-file-types/ Share on other sites More sharing options...
stevesimo Posted May 8, 2007 Author Share Posted May 8, 2007 I managed to fix it using an array containing all the different MIME types $allowed = array ('image/gif', 'image.jpeg', 'image/jpg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/bmp'); if (in_array($_FILES['imagefile']['type'], $allowed)){ //do something with image } Quote Link to comment https://forums.phpfreaks.com/topic/50499-solved-restricting-file-types/#findComment-248154 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.