Jump to content

Check file type


anujgarg

Recommended Posts

Hi

 

I have following query:

 

I need to upload a file on server. Before uploading it, I need to check its type and its genuineness. Suppose, I am willing to uplaod an image file having extension .jpg. But, mistakenly, I renamed a .txt file to .jpg file on my local system and then tried to upload it. I want to avoid this fake .jpg file to get uploaded on server.

 

Will the function filetype() be suitable for that?

Will it check the file type and its behaviour (if it is real .jpg file or not)??

 

Please suggest me if there is some other function for this...

 

TIA

Anuj Garg

 

Link to comment
https://forums.phpfreaks.com/topic/177402-check-file-type/
Share on other sites

It checks the MIME type of the file, which should be irrelevant of the file extension. However bare in mind that the value is set client side so it can be overriden if somebody is attempting to circumvent security, also note that not all browsers use the same MIME types. There was another thread fairly recently on the topic, which suggested using a combination of techniques, if you search the forum you should find it.

Link to comment
https://forums.phpfreaks.com/topic/177402-check-file-type/#findComment-935387
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.