imgrooot Posted December 10, 2017 Share Posted December 10, 2017 I am using this script for image uploads. https://www.w3schools.com/php/php_file_upload.asp I noticed that with some of the image uploads, I would get the error "Sorry, only JPG, JPEG, PNG & GIF files are allowed." The images i upload are one of the file types listed above. So I am wondering why i would get an error for some images but not others despite all them of being the same file types? Can you tell why judging from the script? Quote Link to comment https://forums.phpfreaks.com/topic/305882-is-there-a-reason-why-some-images-wont-upload-using-this-script/ Share on other sites More sharing options...
Solution imgrooot Posted December 10, 2017 Author Solution Share Posted December 10, 2017 I found what the issue was. This code in the script has all lowercase extensions. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {} I had to also add all the UPPERCASE extensions as well. And it worked. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" && $imageFileType != "GIF") {} Quote Link to comment https://forums.phpfreaks.com/topic/305882-is-there-a-reason-why-some-images-wont-upload-using-this-script/#findComment-1554564 Share on other sites More sharing options...
benanamen Posted December 10, 2017 Share Posted December 10, 2017 (edited) Doubling the amount of code you are using is not the answer. strtolower is your friend. Checking just the file extension is also not a good idea. A user can put any file extension they want. Doesn't mean it is a valid file type. You should also be checking the file mime type. Put the extensions in an array and then use in_array to validate. Same with the mime types. w3schools is not the best place to learn from. Edited December 10, 2017 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/305882-is-there-a-reason-why-some-images-wont-upload-using-this-script/#findComment-1554566 Share on other sites More sharing options...
imgrooot Posted December 10, 2017 Author Share Posted December 10, 2017 Doubling the amount of code you are using is not the answer. strtolower is your friend. Checking just the file extension is also not a good idea. A user can put any file extension they want. Doesn't mean it is a valid file type. You should also be checking the file mime type. Put the extensions in an array and then use in_array to validate. Same with the mime types. w3schools is not the best place to learn from. Copy. I will keep that in mind. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/305882-is-there-a-reason-why-some-images-wont-upload-using-this-script/#findComment-1554575 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.