PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
when user submit listings and try to upload pics for logo, the "logo.gif" is uploading file but "logo.jpg" and "logo.png" is error out with the following message:
$PhotoGood = false; // initalization - is not a good photo
$FPhoto = $_FILES['filePhoto'];
if ($FPhoto['size'] < $MaxPhotoSize){
if (($FPhoto['type'] == 'image/gif') || ($FPhoto['type'] == 'image/jpeg') || ($FPhoto['type'] == 'image/png')){
// Good photo
............ // action to take
} else {
print "Invalid photo type!<br />";
} // if (($FPhoto['type'] == 'image/gif') OR ($FPhoto['type'] == 'image/jpeg') OR ($FPhoto['type'] == 'image/png'))
} else {// if ($FPhoto['size'] < $MaxPhotoSize)
print "The photo '".$FPhoto['name']."' is too big (".ceil($FPhoto['size']/1000)." Kb)!<br />Please resize the photo.<br />";
} // if ($FPhoto['size'] < $MaxPhotoSize)
Chekc the value of $_FILES['logoup']['type'] when you get the error message, my guess would be it is not matching your expectations. For example I know I have seen some jpg files in the past that show as type image/pjpg not image/jpg. Depending on what you are doing with the uploaded files, arguably you are better off checking the extension of the file rather than the image type as this is what will determine how the web server serves them later, but assuming you do want to check image type it is probably just a case of extending the list to allow variations.
Never trust $_FILES['upload']['type']. It's data from the user and could be wrong, fake, or an attempt to hack your site. Check the file itself. For images that's easy, just use getimagesize().