mime.lib.php 744 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * MIME detection code.
  5. *
  6. * @package PhpMyAdmin
  7. * @todo Maybe we could try to use fileinfo module if loaded
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /**
  13. * Tries to detect MIME type of content.
  14. *
  15. * @param string &$test First few bytes of content to use for detection
  16. *
  17. * @return string
  18. */
  19. function PMA_detectMIME(&$test)
  20. {
  21. $len = strlen($test);
  22. if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) {
  23. return 'image/jpeg';
  24. }
  25. if ($len >= 3 && substr($test, 0, 3) == 'GIF') {
  26. return 'image/gif';
  27. }
  28. if ($len >= 4 && substr($test, 0, 4) == "\x89PNG") {
  29. return 'image/png';
  30. }
  31. return 'application/octet-stream';
  32. }
  33. ?>