MIME TYPES
Moderator: General Moderators
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
MIME TYPES
Hey,
In a $_FILES upload process the $_FILES['type'] for ANY file being uploaded is always "application/octet-stream" Why is this and is there anyway that I can resolve this using php?
In a $_FILES upload process the $_FILES['type'] for ANY file being uploaded is always "application/octet-stream" Why is this and is there anyway that I can resolve this using php?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: MIME TYPES
The type is set by the browser and you shouldn't rely on it even if it were to appear to be correct. I haven't ever seen it always return application/octet-stream (maybe IE?). One way:
Or on linux if you don't have the file info extension for PHP:
Code: Select all
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = finfo_file($finfo, $_FILES['file']['tmp_name']);Code: Select all
$type = exec('file -bi ' . $_FILES['file']['tmp_name']);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Re: MIME TYPES
I have PHP 5.2 not 5.3
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: MIME TYPES
Well you can use the exec() version above if on linux. I suppose you tried this already?
Code: Select all
$type = mime_content_type($_FILES['file']['tmp_name']);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Re: MIME TYPES
Yeah... but mime_content_type comes back empty for some reason....what gives here? I can't use exec() for security reasonsAbraCadaver wrote:Well you can use the exec() version above if on linux. I suppose you tried this already?
Code: Select all
$type = mime_content_type($_FILES['file']['tmp_name']);
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: MIME TYPES
Not sure. Could be a lot of issues. Maybe it can't determine the type. What does this show?
Code: Select all
echo ini_get('mime_magic.magicfile');mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: MIME TYPES
if i remember right you are going to have a hell of time with this. it would probably be easier to make sure you serve the files as the correct mime type.
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
Re: MIME TYPES
Please elaborate....I ended up having to use finfo() with a content_mime_type() fall back.... I'm curious to find out though why content_mime_type would return an incorrect mime_typedaedalus__ wrote:if i remember right you are going to have a hell of time with this. it would probably be easier to make sure you serve the files as the correct mime type.
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: MIME TYPES
im not sure myself. i dont know what you are using this for either but if someone uploads an image with .x extension and you serve it as an image/x it wont really matter if it was image/x when it got uploaded it just wont display right or at all. i kinda figured this was about security