Jump to content

Archived

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

Lessur

More File Types

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?

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.