I have a large amount of files where their original file names have been replaced by ids from my database. For example, what was once name word_document.doc is now 12345. Through a process I have lost the original name.
I am now trying to present these files for download. The person should be able to download the file and view it using it's original application. The files are all in one of the following formats:
- .txt (text)
- .doc (word document)
- .docx (word document)
- .wpd (word perfect)
- .pdf (PDF)
- .rtf (rich text)
- .sxw (star office)
- .odt (open office)
I'm using
$fhandle = finfo_open(FILEINFO_MIME);
$file_mime_type = finfo_file($fhandle, $filepath);
to get the mime type and then mapping the mime type to an extension.
The problem I am running into is some of the files have a mime type of octet-stream. I've read online and this type seems to be a miscellaneous type for binary files. I can't easily tell what the extension needs to be. In some cases it works when I set it to .wpd and some cases it doesn't. The same goes for .sxw.