JohnDubya
04-04-2007, 07:39 PM
I've built my first file upload script, and I'm needing to be able to validate the files by their mime type, but I'm running into some problems that I can't find answers to via Google or here. Here's an example of the code I'm using so far:
//Check extensions for documents
if ($resource_type == 'document') {
$allowed = array('application/pdf' => 'pdf',
'text/rtf' => 'rtf',
'application/rtf' => 'rtf',
'application/msword' => 'doc',
'application/octet-stream' => 'doc',
'application/vnd.ms-excel' => 'xls',
'application/vnd.ms-publisher' => 'pub',
'application/ppt' => 'ppt',
'application/vnd.ms-powerpoint' => 'ppt',
'text/txt' => 'txt',
'text/plain asc ' => 'txt');
//Check that the uploaded type is allowed.
if (!array_key_exists($_FILES['resource']['type'], $allowed)) {
$Error_Stat = 1;
$Message = Error("That file type is not allowed for documents.");
}
}
So basically, it's looking at the type and making sure it is of certain kinds that I specify. It's working great for most files, but one .doc file I uploaded was the type "application/octet-stream." What is that? I know it should be "application/msword," but why is it different?
//Check extensions for documents
if ($resource_type == 'document') {
$allowed = array('application/pdf' => 'pdf',
'text/rtf' => 'rtf',
'application/rtf' => 'rtf',
'application/msword' => 'doc',
'application/octet-stream' => 'doc',
'application/vnd.ms-excel' => 'xls',
'application/vnd.ms-publisher' => 'pub',
'application/ppt' => 'ppt',
'application/vnd.ms-powerpoint' => 'ppt',
'text/txt' => 'txt',
'text/plain asc ' => 'txt');
//Check that the uploaded type is allowed.
if (!array_key_exists($_FILES['resource']['type'], $allowed)) {
$Error_Stat = 1;
$Message = Error("That file type is not allowed for documents.");
}
}
So basically, it's looking at the type and making sure it is of certain kinds that I specify. It's working great for most files, but one .doc file I uploaded was the type "application/octet-stream." What is that? I know it should be "application/msword," but why is it different?