Guest User

Untitled

a guest
Jun 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function autoDetect($file, $params = false)
  2. {
  3. // Sanity checks
  4. if (!file_exists($file)) {
  5. return PEAR::raiseError("File \"$file\" doesn't exist");
  6. }
  7.  
  8. if (!is_readable($file)) {
  9. return PEAR::raiseError("File \"$file\" is not readable");
  10. }
  11.  
  12. if (function_exists('finfo_file')) {
  13. $finfo = finfo_open(FILEINFO_MIME);
  14. $type = finfo_file($finfo, $file);
  15. finfo_close($finfo);
  16. if ($type !== false && $type !== '') {
  17. return MIME_Type::_handleDetection($type, $params);
  18. }
  19. }
  20.  
  21. if (function_exists('mime_content_type')) {
  22. $type = mime_content_type($file);
  23. if ($type !== false && $type !== '') {
  24. return MIME_Type::_handleDetection($type, $params);
  25. }
  26. }
  27.  
  28. @include_once 'System/Command.php';
  29. if (class_exists('System_Command')) {
  30. return MIME_Type::_handleDetection(
  31. MIME_Type::_fileAutoDetect($file),
  32. $params
  33. );
  34. }
  35.  
  36. require_once 'MIME/Type/Extension.php';
  37. $mte = new MIME_Type_Extension();
  38. return $mte->getMIMEType($file);
  39. }
Add Comment
Please, Sign In to add comment