Jump to content

More File Types


Lessur

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.