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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.