Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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: 730
Name: John
Location: United States of America, California
Trades: 0
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.";
}
}
?>
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

goheadtry is offline
Reply With Quote
View Public Profile Visit goheadtry's homepage!
 
 
Register now for full access!
Old 05-21-2008, 12:51 AM Re: ???Upload script check multiple mime types???
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
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: 730
Name: John
Location: United States of America, California
Trades: 0
Same thing, but how do I avoid fake files?
__________________
Free $1 gift card when you signup at
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

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,226
Name: Mike
Location: Mataro, Spain
Trades: 0
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).
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

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: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
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!
 
Old 01-28-2010, 01:20 PM Re: ???Upload script check multiple mime types???
Junior Talker

Posts: 4
Trades: 0
mtishetsky - Thanks for your reply in this post. It just solved my problem!
purpleman51 is offline
Reply With Quote
View Public Profile
 
Old 01-29-2010, 06:27 PM Re: ???Upload script check multiple mime types???
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
This is practically the same as Mike's example, I just prefer this way
PHP Code:
$mime// file's mime type
$allowed = array('video/x-ms-asf''video/x-msvideo''video/x-flv');
if (
in_array($mime$allowed)) {
   echo 
'Eureka!';

__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 01-30-2010, 01:21 AM Re: ???Upload script check multiple mime types???
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
While on small arrays (up to tens items) using in_array() or isset($array[$key]) is mostly a question of religion, on large arrays (from hundreds items) isset() is significantly faster since it does not have to iterate through array.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to ???Upload script check multiple mime types???
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.47894 seconds with 12 queries