Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
Images
filetypeMatchesExtension($file)
imagelinerectangle()
issa clock
rotate_wide_line($x, $y, $width, $length, $degrees)
4
found
auth
Name:
Category: Images
Body:
// php function to check files function filetypeMatchesExtension($file) { $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $mimeTypes = array( // images 'png' => 'image/png', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'bmp' => 'image/bmp', 'ico' => 'image/vnd.microsoft.icon', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', // adobe 'pdf' => 'application/pdf', 'psd' => 'image/vnd.adobe.photoshop', 'ai' => 'application/postscript', 'eps' => 'application/postscript', // ms office 'ps' => 'application/postscript', 'doc' => 'application/msword', 'rtf' => 'application/rtf', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', // open office 'odt' => 'application/vnd.oasis.opendocument.text', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', ); if (! isset($mimeTypes[$extension])) return false; // unknown is bad, hmkay return mime_content_type($file) === $mimeTypes[$extension]; } // bash checks for existing images/pdfs: // maxdepth refers to subdirectories, mtime to days in the past (124 days ago was the start of 2016 at time of writing) // iname is a case-insensitive filename check (they're just uppercase to mostly-match the `file` output) // print0 (that's a zero) and the corresponding -0 for xargs handles spaces in filenames. $ find . -maxdepth 1 -mtime -124 -iname '*.PDF' -print0 | xargs -0 file | grep -v PDF $ find . -maxdepth 1 -mtime -124 -iname '*.PNG' -print0 | xargs -0 file | grep -v PNG\ image $ find . -maxdepth 1 -mtime -124 -iname '*.JPG' -print0 | xargs -0 file | grep -v JPEG\ image $ find . -maxdepth 1 -mtime -124 -iname '*.JPEG' -print0 | xargs -0 file | grep -v JPEG\ image
Footer