Jump to content

Downloadable products not correct MIME type


Recommended Posts

I am creating custom reports in PDF for sale and download.
I have the correct PDF file in place in the download directory, order it, then when I go to my order details
click on the download button and viola, it shows that it is a TEXT document, see attachment.

Isn't get-file.php supposed to check the MIME type? It is returning 'text/plain' as the MIME type

28564_ASvqtf7GSuxJ74rHGR8i_t

Link to comment
Share on other sites

Ahha!

It is checking the file in the downloads directory instead of renaming it to the "real" filename and then checking it.
The file has NO extension:

/home/mysite/public_html/download/91745deda93a1c2f8426255a7aec9d4995e8ea0d



Any ideas on how to circumvent this problem?

Link to comment
Share on other sites

Alright, more research...Remember, my downloadable file is a PDF but has the filename that is the hash with no extension.

First, why use mime_content_type when it has been declared deprecated? I can understand using it as a fallback when finfo is not installed but it may produce errors or deprecation notices AND won't work at all without PHP being built with the “--with-mime-magic” option.

BTW, here is what is returned by finfo when run on localhost:
'application/octet-stream; charset=binary'


There HAS to be a better way to do this. I KNOW they will always be PDFs, Should I "hardcode" the MIME type in get-file.php for this site?

Link to comment
Share on other sites

Ok, now I'm going nuts.

On localhost:
When I go into the BO and select the product, then click on the filename next to "This is the link:", it gives me the correct MIME type
'application/pdf', even though it uses the same get-file.php script that I've been having problems with above.
Note: on localhost, I have fileinfo enabled, but I'm confused as to why it isn't returning 'application/octet-stream; charset=binary’

On my server:
When I go into the BO and select the product, then click on the filename next to "This is the link:", it gives me the wrong MIME type again,
'text/plain', because it is using the same get-file.php script that I've been having problems with above.

I'm hard coding it for now but need some answers as to how to prevent this if we decide to offer other downloadable products, such as video.

Link to comment
Share on other sites

  • 3 weeks later...

I'm having a similar problem. I've got PS 1.3.1, installed on hostgator... nothing unusual, my cart is http://www.computer-aid.com.au/shop/

I've setup a .exe (CKF.exe) file to be downloaded as a attachment, and it only works if I give the attachment a name that ends in .exe (eg CKF.exe)

But when I add the same .exe as a downloadable product, (and only while using firefox!!!), firefox will say: you have chosen to download CKF.exe, which is a: Text Document.

When I say "save file", it gets saved as: CKF.exe.txt

Sure, if I rename the file to CKF.exe, it will work, but I can't ask nono-technical users to do this.

After having spent days scratching my head over this, I'm just about to abandon Prestashop... Its a nice cart, but I can't tolerate such obvious problems... I need something that works without having to crawl forums, and finding no straightforward solutions.

I've yet to test paypal and a serial generating module... I just don't need the headache!

Link to comment
Share on other sites

I don't see exe as one of the extensions where it checks the MIME type. It is supposed to return the 'application/octet-stream' type if it doesn't find it.
Do you have file_info enabled on your server?

Here are the valid MIME types for exe files:

application/octet-stream, 
application/x-msdownload, 
application/exe, 
application/x-exe, 
application/dos-exe, 
vms/exe, 
application/x-winexe, 
application/msdos-windows, 
application/x-msdos-program



Try adding one of them to the $mimeTypes array (line 116) in get-file.php and see if it works

Link to comment
Share on other sites

the 9th line in the list of mime types in get-file.php has:
'exe' => 'application/octet-stream',

how do I find out if file_info is enabled on my server?

Remember: I'm using shared hosting on hostgator, so I won't be able to change much.

besides, if it works for IE8 and chrome, it should also work for FF.

and: I have other .exe files available from other areas of my website (blog, etc), and they have no problems, and they are available to be downloaded directly from my website (not via any web application like PS or wordpress).

It has to be a bug with PrestaShop, and a major one in my opinion.

Link to comment
Share on other sites

What getfile does is it looks up the record with the key passed in the physically_filename column of ps_product_download.
Then it takes the file with that filename, located in the download directory, and sends it to the browser with the filename
that comes from the display_filename in the record from ps_product_download. This is the code that sends it to the browser:

/* Set headers for download */
header('Content-Transfer-Encoding: binary');
if ($mime_type)
   header('Content-Type: '.$mime_type);
header('Content-Length: '.filesize($file));
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($file);



I will look further into how those headers should be formatted and let you know.
I will come up with a system where you can save your headers to a file and try it in
both browsers to see if they are different.

Link to comment
Share on other sites

  • 2 months later...

Hi guys, I've got a question regarding mime types. One day, I had a huge amount of data from a particular website. Checked the webproxy log to find allowed access to "mime application/x-msdos-program" file, which was considered to .exe file.

Originally, I have policy for web access that states that no Downloading programs where I have created a Site and Content Rule using Content Group that I made where mime types and file extensions are listed (application/octet-stream, application/x-zip-compressed, application/zip, .exe).

Isn't it .exe extension should be listed as an application/octet-stream MIME? Why is it being identified as an application/x-msdos-program MIME type?

Link to comment
Share on other sites

  • 4 weeks later...
×
×
  • Create New...