Lessur Posted July 18, 2006 Share Posted July 18, 2006 I have this code:[CODE]elseif ($_FILES['file']['type'] != 'application/x-shockwave-flash'){echo "Error! file must be SWF <a href='?'>Go back?</a>";}[/CODE] That works, but I want to allow more file types, such as images.I have tried things such as: [CODE]elseif ($_FILES['file']['type'] != 'application/x-shockwave-flash , [insert other mime type here]'){echo "Error! file must be SWF <a href='?'>Go back?</a>";}[/CODE] But they do not work correctly.How can I allow many other filetypes? Link to comment https://forums.phpfreaks.com/topic/14988-more-file-types/ Share on other sites More sharing options...
hvle Posted July 19, 2006 Share Posted July 19, 2006 first, create an array of file type:$allowedtypes = array('type1', 'type2', 'type2');the check if the upload type is allowed:[code]elseif (!in_array($_FILES['file']['type'], $allowedtypes)){ echo "Error! file type is not allowed. <a href='?'>Go back?</a>";}[/code] Link to comment https://forums.phpfreaks.com/topic/14988-more-file-types/#findComment-60238 Share on other sites More sharing options...
hitman6003 Posted July 19, 2006 Share Posted July 19, 2006 Create an array with the file types, then use the in_array (http://www.php.net/in_array) function to determine if it is one of the accepted ones.[code]$filetypes = array('application/x-shockwave-flash', 'another','another','another', etc...);.....elseif (!in_array($_FILES['file']['type'], $filetypes) { echo "error....";]}[/code]EDIT: hvle beat me to it Link to comment https://forums.phpfreaks.com/topic/14988-more-file-types/#findComment-60239 Share on other sites More sharing options...
Lessur Posted July 19, 2006 Author Share Posted July 19, 2006 Thanks, both of you Link to comment https://forums.phpfreaks.com/topic/14988-more-file-types/#findComment-60298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.