ShoeLace1291 Posted September 28, 2007 Share Posted September 28, 2007 I have a user registration script that allows the user to upload a photo. My problem is that I need the photo to be either a JPG, a GIF, or a PNG. I think I have the right idea of how to do this, but I can't get my syntax to work. This is my code for the if statement if its in the correct file format: $photoname = $_FILES['photo']['name']; $phototype = $_FILES['photo']['type']; if(!($phototype == "image/jpeg") || !($phototype == "image/gif") || !($phototype == "image/png")){ echo "The photo you have chosen to upload is in an incorrect file format. Allowed formats are jpeg, gif, and png. You chose a $phototype."; $errors = $errors + 1; } And this is my code for moving the photo: copy( $_FILES['file']['name'], "/photos" ) or die( "There was an error uploading your photo. Please try again later."); I get the error messages that I had echoed if there were an error. This is it: The photo you have chosen to upload is in an incorrect file format. Allowed formats are jpeg, gif, and png. You chose a .There was an error uploading your photo. Please try again later. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/71093-registration-script-with-photo-upload/ Share on other sites More sharing options...
MadTechie Posted September 28, 2007 Share Posted September 28, 2007 try this logic if( ($phototype != "image/jpeg") && ($phototype != "image/gif") && ($phototype != "image/png") ) { also it looks like the type isn't being set, can you post the form.. check the name is "photo" on the input type='file' Quote Link to comment https://forums.phpfreaks.com/topic/71093-registration-script-with-photo-upload/#findComment-357542 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Share Posted September 28, 2007 i don't like using image/jped or whatever else sometimes it bring problems what you can so is $fileName = basename($_FILE['file']['name']); $extension = strtolower(substr($fileName,-4)); switch($extension){ case '.jpg': echo 'good'; break; case '.gif': echo 'good'; break; case '.png': echo 'good'; break; default: echo "The photo you have chosen to upload is in an incorrect file format. Allowed formats are jpeg, gif, and png. You chose a $phototype."; } Quote Link to comment https://forums.phpfreaks.com/topic/71093-registration-script-with-photo-upload/#findComment-357549 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.