Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Return type of file by extension
  5. * @param string $filePath File path/link
  6. * @return string One of: image, pdf, video, other
  7. */
  8. function fileExtensionType($filePath)
  9. {
  10. // types of files (add if necessary)
  11. $fileTypes = [
  12. 'jpg' => 'image', 'jpeg' => 'image', 'png' => 'image', 'bmp' => 'image', 'gif' => 'image',
  13. 'avi' => 'video', 'ogg' => 'video', 'mp4' => 'video', 'mpg' => 'video',
  14. 'pdf' => 'pdf'
  15. ];
  16.  
  17. // calculate the extension
  18. $info = pathinfo($pathinfo);
  19. $extension = $info['extension'];
  20. if (!$extension) {
  21. return "other";
  22. }
  23.  
  24. return isset($fileTypes[$extension]) ? $fileTypes[$extension] : "other";
  25. }
  26. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement