tags:

views:

51

answers:

2

I have an e-commerce package called Prestashop. They allow you to sell virtual products, downloadable items, such as software, e-books, etc.

They have a problem in their software where they name the physical filename of the downloadable product as a 40-char hash with no extension. Then when a customer goes to download the file, the system is supposed to check the MIME type so it can be set in the header before the file is sent to the customer's browser.

Herein lies the problem. They use four methods to determine the MIME type.

  1. finfo_open() function, this extension happens to NOT be installed on my host so it fails.
  2. mime_content_type() function, this takes the file with no extension and returns a 'text/plain' MIME type, no matter what the MIME type actually is. This function has been deprecated and my thoughts are that they shouldn't be using it at all.
  3. exec('file -bi '.escapeshellarg($file)). this fails on my host as well.
  4. an array of extensions to match the MIME type to.

I'm having difficulty figuring this out because of the fact that they name the file, when you add it to the backoffice with no extension. It is difficult for me to see that this ever works at all.

I've tried numerous other fixes, including getting the CURLINFO_CONTENT_TYPE from a cURL call to download the file, which, BTW, returns 'text/plain' for the same file.

Any ideas as to how I can remedy this problem?

A: 

Since you have access to the code, you can change the method of saving a file where it is converted into the hash and add some blocks of code:
1) Before the file is saved, save the extension yourself.
2) After the hash as been generated, append the extension to the file and save that or record it somewhere (datafile, databae, etc)
3) And update anywhere that the hash is generated to take the extension into account.

This might not be a solution to the actual problem with the software, but it should allow you to preserve the filetype...

chustar
I was able to change the code force the mime-type based on the extension of the display_filename, which is the name of the file that the download dialog gets.
MB34
+1  A: 

The getID3 library can recognise PDFs and a bunch of other file types. Check it out:

http://getid3.sourceforge.net/

dazweeja