예제 #1
0
 /**
  * Returns the suggested MIME type for an actual file.  Using file-based heuristics
  * (data points in the ACTUAL file), it will utilize either the PECL FileInfo extension
  * OR the Magic MIME extension (if either are available) to determine the MIME type.  If all
  * else fails, it will fall back to the basic GetMimeTypeForFilename() method.
  *
  * @param string $strFilePath the absolute file path of the ACTUAL file
  * @return string
  */
 public static function GetMimeTypeForFile($strFilePath)
 {
     // Clean up the File Path and pull out the filename
     $strRealPath = realpath($strFilePath);
     if (!is_file($strRealPath)) {
         throw new QCallerException('File Not Found: ' . $strFilePath);
     }
     $strFilename = basename($strRealPath);
     $strToReturn = null;
     // First attempt using the PECL FileInfo extension
     if (class_exists('finfo')) {
         if (QMimeType::$MagicDatabaseFilePath) {
             $objFileInfo = new finfo(FILEINFO_MIME, QMimeType::$MagicDatabaseFilePath);
         } else {
             $objFileInfo = new finfo(FILEINFO_MIME);
         }
         $strToReturn = $objFileInfo->file($strRealPath);
     }
     // Next, attempt using the legacy MIME Magic extension
     if (!$strToReturn && function_exists('mime_content_type')) {
         $strToReturn = mime_content_type($strRealPath);
     }
     // Finally, use Qcodo's owns method for determining MIME type
     if (!$strToReturn) {
         $strToReturn = QMimeType::GetMimeTypeForFilename($strFilename);
     }
     if ($strToReturn) {
         return $strToReturn;
     } else {
         return QMimeType::_Default;
     }
 }
예제 #2
0
 /**
  * Given a file at a temp file path location, this will save the file to the repository
  * and save the db row record.
  * @param string $strTemporaryFilePath the temporary file path to the file being saved to the repository
  * @param string $strFileName the name of the file that was originally uploaded
  * @return void
  */
 public function SaveFile($strTemporaryFilePath, $strFileName)
 {
     // Update wiki file metadata
     $this->FileName = $strFileName;
     $this->FileSize = filesize($strTemporaryFilePath);
     $this->FileMime = QMimeType::GetMimeTypeForFilename($strFileName);
     // Save the Row
     $this->Save();
     // Copy the File
     QApplication::MakeDirectory($this->GetFolder(), 0777);
     copy($strTemporaryFilePath, $this->GetPath());
     chmod($this->GetPath(), 0666);
 }