tjodolv Posted August 5, 2007 Share Posted August 5, 2007 I am writing a script for uploading files. I want the script to only accept certain filetypes, in order to avoid any bad content. I figured I could do it by checking the MIME-type, or perhaps the file-ending. However, there are quite a number of filetypes I would like to allow, and so I am wondering if I could get some pointers to a more elegant solution than simply "brute-forcing" my way through all the different filetypes.? Quote Link to comment https://forums.phpfreaks.com/topic/63444-solved-file-type-validation/ Share on other sites More sharing options...
Fadion Posted August 5, 2007 Share Posted August 5, 2007 The brute force should be: $ext = strtolower(substr(strrchr($filename, '.'), 1)); if($ext == 'jpg' or $ext == 'doc' etc etc){ ...some code } or $ext = strtolower(substr(strrchr($filename, '.'), 1)); $allowedExt = array('jpg', 'doc' etc etc); if(in_array($ext, $allowedExt){ ...some code } U can fill the array with the allowed extension types and u'll have a much cleaner code, i guess . Dont know of any other method. Quote Link to comment https://forums.phpfreaks.com/topic/63444-solved-file-type-validation/#findComment-316175 Share on other sites More sharing options...
tjodolv Posted August 6, 2007 Author Share Posted August 6, 2007 ok.. Well, more elegant than my own n00bish attempt at brute-force, so thanks Quote Link to comment https://forums.phpfreaks.com/topic/63444-solved-file-type-validation/#findComment-316833 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.