I am storing a file in a MySQL BLOB field using PHP. Latter I am trying to send that BLOB data as an attachment in mail.
My question is: how can I get the type of the BLOB object in PHP? That BLOB object can be a PDF or Word file. Without knowing the file type, we can’t send the mail.
Please suggest me the solution, thanks .
The original file type of the data of a BLOB object is not stored in MySQL, thus one cannot know what file type a file is, instantly.
In order to get the file type, you can do certain things:
%PDF, for Word files the signature consists of these bytes (displayed in hexadecimals):50 4B 03 04 14 00 06 00. I’ve found a table where you can find many file signatures. Notice that checking the signature does not apply to all file formats.