// CHECK TO SEE IF UPLOADED RESUME IS OF AN ILLEGITIMATE FILE MIME TYPE
if ($this->isValid && is_file($_FILES['resume_doc']['tmp_name']) &&
@!in_array(preg_replace('/^([a-zA-Z0-9\-_\.]+\/[a-zA-Z0-9\-_\.]+)/i', '$1', mime_content_type($_FILES['resume_doc']['tmp_name'])),
array_values($acceptableMimePrefixArray)) &&
@!in_array(substr($_FILES['resume_doc']['name'], strrpos($_FILES['resume_doc']['name'], '.'), strlen($_FILES['resume_doc']['name'])),
array_keys($acceptableMimePrefixArray)
)
) {
$this->isValid = false;
$this->setErrorArray(array('resume_doc' => 'Your uploaded resume is not one of the accepted MIME prefix types: ' .
str_replace(',', ', ', @join(',', array_keys($acceptableMimePrefixArray)))));
}
I have an application due Friday 4/21 AM and I am completely stuck on this snippet of code!!
I am having to determine that an uploaded file is one of four types:
1) Text
2) MS Word doc
3) RTF
4) Adobe PDF
This code snippet, however, does not work, using this as $acceptableMimePrefixArray:
$acceptableMimePrefixArray = array('txt' => 'text/plain', 'doc' => 'application/msword', 'rtf' => 'text/rtf', 'pdf' => 'application/pdf');
And this is the potential redefinition of 'mime_content_type' for PHP versions that do not support this function:
/*-----------------------------------------------------------------------------------------------------------------------
Note: Certain variations of PHP may not have these functions installed within php.ini if this is
the case these functions will kick in instead
------------------------------------------------------------------------------------------------------------------------*/
if (!function_exists('mime_content_type')) {
/**
* Note: Certain variations of PHP may not have these functions installed within php.ini if this is the case these functions will kick in instead
*
* @access public
* @param mixed $file
* @return mixed UNIX
* @link [url]http://us3.php.net/manual/en/function.mime-content-type.php#50756[/url]
* @see link regarding usage of mime_content_type in Windows platform
*/
function mime_content_type($file) {
global $windowsMagicMimePath;
if (!$_ENV['windir']) return exec('file -bi ' . escapeshellarg($file)); // STOP HERE, WILL WORK IN UNIX
$array = @getimagesize($file); // OBTAIN INFORMATION - WILL PARTITION IF FILE IS IMAGE OR NOT
return $array['mime']; // SHOULD EITHER RETURN A MIME TYPE OR NOTHING
}
}
Since I'm under the gun here, I'll just cut to the chase. Using the above code snippet, I am getting bizarre results as far as the return value of mime_content_type() is concerned; I cannot remove anything after the ";" (provided one is returned, sometimes it is not); and I cannot even get a consistent MIME type:
1) One .log file returned as "text/v-c++"
2) One .xls file returned as "text/plain"
3) One other .xls file returned as "application/msword"
4) One .txt file returned as "image/png"
I really need something and something FAST!!!
Thanx
Phil