Jump to content


Photo

More File Types


  • Please log in to reply
3 replies to this topic

#1 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 18 July 2006 - 11:40 PM

I have this code:

elseif ($_FILES['file']['type'] != 'application/x-shockwave-flash')

{

echo "Error! file must be SWF <a href='?'>Go back?</a>";

}


That works, but I want to allow more file types, such as images.

I have tried things such as:
elseif ($_FILES['file']['type'] != 'application/x-shockwave-flash , [insert other mime type here]')

{

echo "Error! file must be SWF <a href='?'>Go back?</a>";

}
  But they do not work correctly.

How can I allow many other filetypes?

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 19 July 2006 - 12:15 AM

first, create an array of file type:
$allowedtypes = array('type1', 'type2', 'type2');

the check if the upload type is allowed:

elseif (!in_array($_FILES['file']['type'], $allowedtypes))
{
   echo "Error! file type is not allowed. <a href='?'>Go back?</a>";

}

Life's too short for arguing.

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 19 July 2006 - 12:18 AM

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.

$filetypes = array('application/x-shockwave-flash', 'another','another','another', etc...);

.....
elseif (!in_array($_FILES['file']['type'], $filetypes) {
  echo "error....";]
}

EDIT: hvle beat me to it

#4 Lessur

Lessur
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 19 July 2006 - 01:50 AM

Thanks, both of you




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users