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? Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Lessur Posted July 19, 2006 Author Share Posted July 19, 2006 Thanks, both of you Quote Link to comment 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.