Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Return type of file by extension
- * @param string $filePath File path/link
- * @return string One of: image, pdf, video, other
- */
- function fileExtensionType($filePath)
- {
- // types of files (add if necessary)
- $fileTypes = [
- 'jpg' => 'image', 'jpeg' => 'image', 'png' => 'image', 'bmp' => 'image', 'gif' => 'image',
- 'avi' => 'video', 'ogg' => 'video', 'mp4' => 'video', 'mpg' => 'video',
- 'pdf' => 'pdf'
- ];
- // calculate the extension
- $info = pathinfo($pathinfo);
- $extension = $info['extension'];
- if (!$extension) {
- return "other";
- }
- return isset($fileTypes[$extension]) ? $fileTypes[$extension] : "other";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement