André
André

Reputation: 25554

What PHP function will give me the type of file?

I'm getting a file with "file_get_contents", there is any PHP Function that will give me the type of the file? In this example "jpg".

$imagedata = file_get_contents("/path/to/image.jpg");      

Please give me some clues.

Best Regards,

Upvotes: 0

Views: 92

Answers (2)

orlp
orlp

Reputation: 117641

The word you are looking for is extension.

$ext = pathinfo($file, PATHINFO_EXTENSION);

This is an exact duplicate of How to extract a file extension in PHP? though, try searching a bit better next time.

Upvotes: 1

alexn
alexn

Reputation: 58952

You can use pathinfo like this:

$extension = pathinfo($filename, PATHINFO_EXTENSION); // jpg

Note that since this fetch the extension from the filename, it can easily be manipulated. You should use a function like getimagesize to determine if a file is a real image.

Upvotes: 1

Related Questions