Jump to content

Digital product MIME type is wrong - text/plain rather than application/zip


Recommended Posts

I ran into a problem today with a customer whose browser was attempting to open a digital product (a zip file) as a text file. Upon investigation I found that the MIME type being reported was text/plain rather than application/zip. The following is the header that was sent (minus the actual URL and filename).

 

http://someurl/blah blah
HTTP/1.1 200 OK
Date: Wed, 13 Feb 2013 16:46:12 GMT
Server: Apache
Content-Transfer-Encoding: binary
Content-Disposition: attachment; filename="SomeFile.zip"
Content-Length: 84593971
Content-Type: text/plain;charset=utf-8

 

I did some digging and was able to "fix" the issue by bypassing a couple of the mime detection attempts in controllers/front/GetFileController.php.

 

Specifically I added 'false &&' onto the first two branch conditions:

$mimeType = false;
if (false && function_exists('finfo_open'))
{
    $finfo = @finfo_open(FILEINFO_MIME);
    $mimeType = @finfo_file($finfo, $file);
    @finfo_close($finfo);
}
else if (false && function_exists('mime_content_type'))
    $mimeType = @mime_content_type($file);

 

After looking at the code further, it appears that finfo_open and mime_content_type are being passed the digital file in the download directory which, by default, doesn't have an extension. I don't know the internals of either function, but could this be the reason that the functions are returning the wrong type? If so, then it could be conceivable that many other people are experiencing this problem in the Prestashop world. Any others have this issue? Is there a better fix?

Link to comment
Share on other sites

Hello Elameno,

 

I did a little digging into your problem. First, I did check the bug tracker, but the issue you're reporting doesn't appear to be a major issue - and it would be since it has to do with digital downloads. Are you able to duplicate the issue in other systems? Just to confirm - are you running the latest version of Prestashop? And do you have a test link that we can try to troubleshoot?

 

I think we just need a little more info and we can try to help.

 

Arnel C.

Web Hosting Hub

Link to comment
Share on other sites

Hello Arnel. Thanks for your quick reply! I have not yet tried to duplicate the issue on any other systems so I don't know if the problem would occur in a non-hostgator environment. My hunch is that it is a more widespread problem though. I'm currently running 1.5.2.0 and can't easily upgrade Prestashop because I have more than a few of my own patches to the system that I don't want to obliterate.

 

I do have a couple of git repositories set up to assist in the upgrade so I can theoretically make the update without clobbering any of the bug fixes I've personally made to the system, but I need to set aside a good chunk of time to make that happen (probably not today).

 

Any URL that I could give you wouldn't display the problem because I've already "fixed" it by disabling those two code blocks with the if(false && ....). The download now reports a mime type of 'application/zip' as it should. Rest assured though, that when those code blocks are enabled the file mime type is set to 'text/plain' rather than 'application/zip'. When that is the case, not so tech-savvy users have contacted me reporting, "All I get when I click the link is a weird text file".

 

Once again, thanks so much for the quick response. Do you run systems that serve digital downloads? Do you see any mime type issues? Just FYI, depending on the user's browser the improper mime-type can be a non-issue. For example: Chrome downloads the file as a zip even when the mime type is wrong; however, Firefox tries to download and save it as a txt file.

  • Like 1
Link to comment
Share on other sites

Hello Elameno,

 

Thanks for the explanation. I work for a web hosting company where we have developed a community support team looking for topics (like this) that our customers might run into so that we can develop documentation for solutions for common problems. I appreciate you pointing out the issue and the version you're using. I actually do have several test servers running and I do have 1.5.20, so I'll double-check the MIME issue there. If I can duplicate the issue, I'll send in a bug report, but I'll also look for a solution for the issue without waiting on Prestashop. Hopefully we can find something soon.

 

If I am unable to duplicate the issue, is it possible for you to provide test links so that we can see what's happening from your end? Especially, since you may have some user specific changes that are not part of a generic installation. I'll reply soon after researching the issue with my team.

 

Regards,

 

Arnel C.

Web Hosting Hub

Link to comment
Share on other sites

  • 1 month later...

I have exactly the same issue and customers using IE and Safari have reported it but I'm unable to duplicate it on my own tests.

 

I'm running 1.5.2 and also unable to upgrade now due to many personalization. Will try to add the changes suggested by elameno and wait if some other customer reports again.

 

Thanks for any help.

Link to comment
Share on other sites

  • 1 year later...
×
×
  • Create New...