ZIP Downloads

Open to all! Ask other shopowners for help.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

ZIP Downloads

Post by heatherbell »

Using a v1.0.8.15 (and also tested on a clean v1.0.8.17) on PHP 8.0
A Download product with a .zip file.
After checkout, can download the .zip but when trying to unzip, message shows on Windows to effect of " cannot unzip, file invalid".
Download the .zip direct from server (ftp) and no problem unzipping.
Don't know if this to do with a change to core or a change to server.
Maybe somebody can test or give a pointer.


Join The Code Co-op to get access to your library in the Code Co-op Forum
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: ZIP Downloads

Post by heatherbell »

Just tested on a v1.0.8.0 with PHP 7.4 on same server and downloads and unzips as expected.
So guess the issue is either with core or PHP version.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: ZIP Downloads

Post by ecartz »

Are the resulting files the same size? If not, what sizes are they? Exact byte counts are preferable here.

Are you using DOWNLOAD_BY_REDIRECT true or false?

Does 1.08.15 or 17 work on PHP 7.4?

If you can reproduce this with a small file, it might make sense to post the files here, both the working and unworking. I'd suggest trying to zip a small text file with at least one new line.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: ZIP Downloads

Post by heatherbell »

ecartz wrote: Sun Aug 28, 2022 4:49 pm Are the resulting files the same size?
Yes, for all except this one. Original zip 297kb, downloaded zip 298kb. Guessing that's just an anomaly as other zips tested were the same file size (tried with several test zips but with same results). I have uploaded these here just because of that 1kb difference.
ecartz wrote: Sun Aug 28, 2022 4:49 pm Are you using DOWNLOAD_BY_REDIRECT true or false?
Tried both with same result.
ecartz wrote: Sun Aug 28, 2022 4:49 pm Does 1.08.15 or 17 work on PHP 7.4?
No, same result on 7.4 and 8.0.
Screenshot 2022-08-29 070609.png
ecartz wrote: Sun Aug 28, 2022 4:49 pm post the files here, both the working and unworking
You do not have the required permissions to view the files attached to this post.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: ZIP Downloads

Post by ecartz »

To add to the confusion:

1. I tried the working file, which I think is the 297 byte (not kb) one. It works fine for me.
2. I was able to set the text file as a downloadable attribute and that worked for me.
3. I was able to set the zip file as a downloadable attribute and that worked for me.
4. For some reason, the non-working zip got further munged while I was trying to work on it. So I copied the file by FTP again. The difference between your working file and your non-working file is that the non-working file has a space at the beginning.

So I'm thinking that one of the files in your installation is corrupt and has a space before the <?php at the beginning. Try application_top.php, as I think that that got corrupted once.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: ZIP Downloads

Post by heatherbell »

ecartz wrote: Mon Aug 29, 2022 10:56 am So I'm thinking that one of the files in your installation is corrupt and has a space before the <?php at the beginning. Try application_top.php, as I think that that got corrupted once.
Many thanks for taking the time to test.
Sadly (or maybe not), application_top has no space before <?php.
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: ZIP Downloads

Post by heatherbell »

ecartz wrote: Mon Aug 29, 2022 10:56 am So I'm thinking that one of the files in your installation is corrupt and has a space before the <?php at the beginning. Try application_top.php, as I think that that got corrupted once.
Just did another test on a brand new 1.0.8.17 installation on a different server and with a different zip (just in case) but same result of "invalid" when downloaded after checkout.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: ZIP Downloads

Post by ecartz »

The next most likely files would probably be the language files, english.php and english/download.php -- after that, the download.php file in the catalog directory. After that, anything else loaded by download.php directly or indirectly (e.g. includes/system/autoloader.php).

Note that the 1.0.8.17 version of english/download.php has a ?> in it, so the space could also appear after that. That's also true of other files with ?> in them. In general, only files with HTML in them should have ?> in them, and download.php shouldn't be loading any of those.

If the space is being added by readfile, I don't see any evidence that anyone else is experiencing the same problem.

Are either test server publicly available? I.e. could I try to download a zip from your test servers?

Also, how are you getting the zips to the server?
heatherbell
Senior Contributor
Posts: 2540
Joined: Mon Oct 07, 2019 4:39 am
Phoenix Version:
Has thanked: 35 times
Been thanked: 243 times

Re: ZIP Downloads

Post by heatherbell »

ecartz wrote: Mon Aug 29, 2022 2:29 pm Are either test server publicly available? I.e. could I try to download a zip from your test servers?
Thank you - see PM for link.
ecartz wrote: Mon Aug 29, 2022 2:29 pm Also, how are you getting the zips to the server?
FTP, WinSCP though the zip can be downloaded from the server and unzipped without issue with FTP.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: ZIP Downloads

Post by ecartz »

You might try the following in download.php:

Code: Select all

set_error_handler(function ($severity, $message, $file, $line, $context) {
  if (error_reporting() & $severity) {
    throw new ErrorException($message, 0, $severity, $file, $line);
  }
});
ob_start();

require 'includes/application_top.php';

if (ob_get_contents()) {
  $message = sprintf("Unneeded output:  [%s]", ob_get_clean());
  error_log($message);
  die(ini_get('display_errors') ? $message : 'Download generation failed');
}

ob_end_clean();
The require line is already in the file and is there just to show where the rest goes.

I suspect that this would be a good idea regardless, but it would be nice to confirm that it works as expected in the failure cases.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply