diff options
author | alexvitkov <44268717+alexvitkov@users.noreply.github.com> | 2021-01-29 12:52:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-29 12:52:06 +0200 |
commit | 33e533d28dbf9ad7bfc7ad9af467e5efe25ae8a0 (patch) | |
tree | 7b748d2b87ab018d7ff451b4111a1b88eeb58416 /php/file_type_recogniser.php | |
parent | ceedd596c9f39f53555fd0746a42d6b85cd49b6c (diff) | |
parent | 472e170f408e3d8d1db2eb066d445153aad55d73 (diff) | |
download | fileup-33e533d28dbf9ad7bfc7ad9af467e5efe25ae8a0.tar.gz |
Merge pull request #1 from GTSimeonov/master
rararrararararraar
Diffstat (limited to 'php/file_type_recogniser.php')
-rw-r--r-- | php/file_type_recogniser.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/php/file_type_recogniser.php b/php/file_type_recogniser.php new file mode 100644 index 0000000..f160fb7 --- /dev/null +++ b/php/file_type_recogniser.php @@ -0,0 +1,84 @@ +<?php + +function file_type($path_to_file) { + $file_type_database = new finfo(FILEINFO_SYMLINK|FILEINFO_MIME_TYPE); + return $file_type_database->file($path_to_file); +} + + +function file_extension($path_to_file) { + #FILEINFO_EXTENSION introduced in php7.2.0 https://www.php.net/manual/en/fileinfo.constants.php + if(defined("FILEINFO_EXTENSION")) + { + $file_type_database = new finfo(FILEINFO_EXTENSION); + return "." . $file_type_database->file($path_to_file); + }else + { + $result=file_type($path_to_file); + + $optimus_prime = array( + 'text/plain'=>'.txt', + 'text/html'=>'.html', + 'text/php'=>'.php', + 'text/css'=>'.css', + 'application/javascript'=>'.js', + 'application/json'=>'.json', + 'application/xml'=>'.xml', + 'application/x-shockwave-flash'=>'.swf', + 'video/x-flv'=>'.flv', + 'image/png'=>'.png', + 'image/jpeg'=>'.jpe', + 'image/jpeg'=>'.jpeg', + 'image/jpeg'=>'.jpg', + 'image/gif'=>'.gif', + 'image/bmp'=>'.bmp', + 'image/vnd.microsoft.icon'=>'.ico', + 'image/tiff'=>'.tiff', + 'image/tiff'=>'.tif', + 'image/svg+xml'=>'.svg', + 'image/svg+xml'=>'.svgz', + 'application/zip'=>'.zip', + 'application/x-rar-compressed'=>'.rar', + 'application/x-msdownload'=>'.exe', + 'application/x-msdownload'=>'.msi', + 'application/vnd.ms-cab-compressed'=>'.cab', + 'audio/mpeg'=>'.mp3', + 'video/quicktime'=>'.qt', + 'video/quicktime'=>'.mov', + 'application/pdf'=>'.pdf', + 'image/vnd.adobe.photoshop'=>'.psd', + 'application/postscript'=>'.ai', + 'application/postscript'=>'.eps', + 'application/postscript'=>'.ps', + 'application/msword'=>'.doc', + 'application/rtf'=>'.rtf', + 'application/vnd.ms-excel'=>'.xls', + 'application/vnd.ms-powerpoint'=>'.ppt', + 'application/vnd.oasis.opendocument.text'=>'.odt', + 'application/vnd.oasis.opendocument.spreadsheet'=>'.ods' + ); + + if(!array_key_exists($result,$optimus_prime)) + { + return ".dat"; + }else + { + return $optimus_prime[$result]; + } + + } +} + +function get_icon($path_to_file) +{ + $file_ext="svg/icons/".file_extension($path_to_file).".svg"; + if(!file_exists($file_ext)) + { + return "svg/icons/.dat.svg"; + }else + { + return $file_ext; + } +} + +?> |