Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if file is JPEG, PDF or TIFF

Tags:

file

php

How would i check that a file is either jpeg, pdf or tiff? And I mean actually checking, not just from mime type and file extension.

I have access to the raw file data (this check is part of an uploader) and i need to verify that the files are either jpeg, pdf or tiff. I assume I would have to check for some sort of headers in the files but I have no idea what to look for and where to start.

like image 678
Ozzy Avatar asked Jan 09 '13 15:01

Ozzy


People also ask

How can I tell if a file is JPEG?

Most digital photos are saved in JPEG format. If you are having trouble and want to check if you photo is a JPEG, look at the writing under the photo in its file name. If it ends . jpg or .

How do I identify a TIFF file?

You can use exiftool to determine whether a TIF file contains compressed data. TIFFs are containers. Unless you put them into another container (zip), they themselves are not compressed. It's the (image) data contained within them that is compressed.

How do I know if my image is JPEG or PNG?

Open a file in a Hex editor (or just a binary file viewer). PNG files start with 'PNG', . jpg files should have 'exif'or 'JFIF' somewhere in the beginning.

Is PDF and TIFF the same?

TIFF files can be significantly smaller than a pdf and converted into a single page. In most cases you can view a TIFF file much faster because it's quicker to index. Adding details: Adding signature forms, new pages, amendments and more can be fairly simple to do on a single page TIFF compared to a PDF.


1 Answers

Exif_imagetype is very useful for this: http://us2.php.net/manual/en/function.exif-imagetype.php

It scans the initial bytes of the file to determine the graphic type. It supports a large number of graphic formats (and returns false if it doesn't recognize the format).

like image 121
dethtron5000 Avatar answered Oct 06 '22 01:10

dethtron5000