/** * Uses variants of the UNIX "file" command to attempt to determine the * MIME type of an unknown byte stream. * * @access public * @param string $data The file data to analyze. * @return string The MIME type of the file. Returns false if either * the file type isn't recognized or the file command is * not available. */ function analyzeData($data) { /* Use a built-in magic file. */ $mime_magic =& DOCMAN_MIME_Magic::_getMimeMagicFile(); foreach ($mime_magic as $offset => $odata) { foreach ($odata as $length => $ldata) { $lookup = substr($data, $offset, $length); if (!empty($ldata[$lookup])) { return $ldata[$lookup]; } } } return false; }
/** * Validate file extension * * @desc This is the function handling the file extension validation when uploading. * @param void * @return boolean Returns true if extension is valid and false if not. Sets $this->err with error message if false. */ function validateExt($name) { if (!$name) { return false; } if (!$this->ext_array) { return true; } $valid_ext = preg_replace("/^[.](.*)\$/", "\$1", $this->ext_array); // Simple lookup first ... $extension = @strtolower(@substr($name, strrpos($name, ".") + 1)); if ($extension && in_array($extension, $valid_ext)) { return true; } // Translate to mimetype for wider test... $extension = DOCMAN_MIME_Magic::MIMEToExt(DOCMAN_MIME_Magic::filenameToMIME($name)); if (in_array($extension, $valid_ext)) { return true; } $this->_err .= _DML_FILETYPE . " "" . $extension . "" " . _DML_NOTPERMITED; return false; }