geroid Posted May 25, 2009 Share Posted May 25, 2009 Further to my previous post. I'm checking the extension of an upload to see if it's valid. I only want images file. I have the following questions: 1. Am I including all the possible extensions here? Are there any more I should be including. 2. What is a good max file size limit for an image file? 3. Should I forget the max file size limit and simply resize the image? 4. How do I mark a post as solved? I use the following test: if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h3>This is an unknown file extension! Please try again</h3>'; $errors=1; Link to comment https://forums.phpfreaks.com/topic/159556-how-many-extension-to-test-for-problem/ Share on other sites More sharing options...
waynew Posted May 25, 2009 Share Posted May 25, 2009 $allowed_filetypes = array("image/gif"=>".gif","image/jpeg"=>".jpeg","image/pjpeg"=>".jpeg"); if(!array_key_exists($_FILES['uploadedfile']['type'],$allowed_filetypes)){ return false; } Link to comment https://forums.phpfreaks.com/topic/159556-how-many-extension-to-test-for-problem/#findComment-841629 Share on other sites More sharing options...
trq Posted May 25, 2009 Share Posted May 25, 2009 The best way to check if an uploaded file is an image is to run it through getimagesize, this will return false if the file is not an image. File extension meen nothing to Linux, hence theres no point relying upon the to determine a file type. Link to comment https://forums.phpfreaks.com/topic/159556-how-many-extension-to-test-for-problem/#findComment-841630 Share on other sites More sharing options...
geroid Posted May 25, 2009 Author Share Posted May 25, 2009 Thanks. I'm looking at getimagesize function now. Can I just ask if the size of an image is important? That is does it matter? If I am going to restrict upload based on the image size, then what should the size limit be and as I said, should I just determine the size and resize accordingly instead of restricting. Link to comment https://forums.phpfreaks.com/topic/159556-how-many-extension-to-test-for-problem/#findComment-841635 Share on other sites More sharing options...
trq Posted May 25, 2009 Share Posted May 25, 2009 Quote Can I just ask if the size of an image is important? Only you can answer that. I doupt you'll want people uploading 500mg files though. Link to comment https://forums.phpfreaks.com/topic/159556-how-many-extension-to-test-for-problem/#findComment-841639 Share on other sites More sharing options...
geroid Posted May 25, 2009 Author Share Posted May 25, 2009 Hi thorpe Just two things. Can you give me a sensible limit to work with? The second thing is this. If I use the getimagesize function to determine if its an image or not will this be safe. What I mean is there are many types of images files. Will getimagesize recognise them but more importantly, would a browser be able to handle them or should I just confine the type tp jpeg, gif, png etc.? Link to comment https://forums.phpfreaks.com/topic/159556-how-many-extension-to-test-for-problem/#findComment-841648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.