Reply
???Upload script check multiple mime types???
Old 05-21-2008, 12:33 AM ???Upload script check multiple mime types???
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
I am trying to check multiple mime types for an uploaded file, but I am unsure of how to check to see if it is more then one mime type so far it only checks against one, so how do I make it check to see if it is one of several mime types?


Here is my code it currently only checks for mime type video/x-ms-asf, but I need it to check all of these mime types.
video/x-ms-asf
video/x-msvideo
video/x-flv
video/quicktime
video/mp4
video/mpeg
video/x-ms-wmv

how do I do this?
PHP Code:
<?php
//home/forbushj/www/vidtemp/
$target "vidtemp/";
$target $target basename$_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size 350000)
{
echo 
"Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if (!($uploaded_type=="video/x-ms-asf")) {
echo 
"You may only upload movies.<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo 
"Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo 
"The file "basename$_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo 
"Sorry, there was a problem uploading your file.";
}
}
?>
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
When You Register, These Ads Go Away!
Old 05-21-2008, 12:51 AM Re: ???Upload script check multiple mime types???
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
You need to edit:
PHP Code:
if (!($uploaded_type=="video/x-ms-asf")) {
echo 
"You may only upload movies.<br>";
$ok=0;

Try:
PHP Code:
if($uploaded_type != "video/x-ms-asf" || $uploaded_type != "video/x-msvideo"
Adding a new || $uploaded_type != "video/*" for each. || is OR and && is AND.
Just a warning, only IE 7+ analyzes the file contents to hand you this, all other browsers simply look at the extension. So if I uploaded an executable with the correct extension it'd fake it.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 05-21-2008, 07:58 PM how do I avoid fakes??
goheadtry's Avatar
Webmaster Talker

Posts: 715
Name: John
Location: United States of America, California
Same thing, but how do I avoid fake files?
goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
Old 05-22-2008, 04:35 AM Re: ???Upload script check multiple mime types???
mtishetsky's Avatar
King Spam Talker

Posts: 1,044
Name: Mike
Location: Mataro, Spain
PHP Code:
$allowed['video/x-ms-asf'] = 1;
...
$allowed['video/x-ms-wmv'] = 1;
...
if (isset(
$allowed[$mime_type])) {
   
proceed();

Considering "fake files": you cannot validate the file by mime-type, you will have to check it with `file` comman-line utility (should be pre-installed on most *nix servers) or try to identify it with some utility that should recorgnize the specified format (e.g. ffmpeg).
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 06-04-2008, 07:19 PM Re: ???Upload script check multiple mime types???
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
Just an extra about this, file says Firefox's key3.db is Berkeley DB, I tried opening it with Berkeley and it stated that it's not Berkeley.
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Reply     « Reply to ???Upload script check multiple mime types???
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.77431 seconds with 12 queries