News:

Support the VirtueMart project and become a member

Main Menu

SOLVED: ZIP file download fails

Started by innato, October 05, 2016, 20:24:00 PM

Previous topic - Next topic

innato

This may not be a VM issue at all, but I am just wondering if someone else has the same problem and - above all - a solution!!

Using VM3.0.18 on J3.6.2 and PHP 5.6.26.
I have isTraxx virtual download plugin installed with my VM3 webshop where I offer PHP software in the form of ZIP file downloads (zipped with WinZip v19.5 Pro). If I complete an order and click the file download link, the file can be downloaded to disk and the file size is OK. But when I try to unzip the downloaded file with WinZip, there is an error saying that the file is an invalid archive (see attached picture).
If I download the same ZIP file from its server location through FTP (i.e. the same source as the VM download), the file size is the same and the file can be unzipped with the same WinZip app without problems.
Curiously, if the downloaded file is a PDF file, there is no problem at all. If the file is a JPG image, I have the same issue (error "cannot open file"). I have not tested other file formats.
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

GJC Web Design

I don't know if this is the prob but we had a lot of problems with PhocaDownloads with similar symptoms

It was with jpgs .. we would get an invalid file error after downloading but we knew the images were perfect

I found the reason.. for some reason an extra blank line was added to the file by the Phoca thing .. u could see it if u opened the jpg in a txt editor
sadly never found a solution..  they now use a different file download extension

try opening the local copy and the downloaded in say Notepad++  and see if they are byte for byte the same
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

innato

Wow GJC!! You are amazing. You are completely right, there was an extra character (ascii 10) added at the beginning of the file. When I removed it, the file was recognised again.
Strange enough I had compared both files (downloaded vs FTP-ed) using CSDiff file comparison prog, but it said that the files were identical. Also the files sizes were identical (probably made equal by adding an additional ascii 0).
I'll investigate further and also open a ticket with isTraxx.
Many thanks and again my compliments!!
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

GJC Web Design

Thanks-- but sadly we never got to the bottom of the problem
It does seem to be server related as I have never seen it on any of my clients installs using Istraxx etc
the one above was a blow in client

I did get as far as this  answer -- suggesting white space in the php file serving the file

from Stack Overflow

###############

My guess would be that you're outputting white-space characters in your PHP code. Probably line feeds. This is a very common cause of file corruption when serving binary files via PHP, and can be hard to spot. It is also very typical of cases where some file types are corrupted and others aren't, because some file types can cope with the extra white space.

White space can creep into a PHP program very easily, simply by having line feeds in your source code outside of the <?php and ?> markers.

Check your PHP program - and all your includes - to ensure they don't have any trailing blank lines after the closing ?> at the end of the program. Also check at the top of the files before the <?php marker, but blank lines at the end of the program is much more common.

###############

so what is required is to go thru the files serving the download file and eliminate all whitespace if the above is correct
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

innato

Quote from: GJC Web Design on October 06, 2016, 13:39:22 PM
so what is required is to go thru the files serving the download file and eliminate all whitespace if the above is correct
That is exactly what I intend to do. If I find something useful, I will post it here.
Thanks again and regards.
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

innato

#5
= PROBLEM SOLVED =
The isTraxx virtual download plug-in includes the file /plugins/vmcustom/istraxx_download/istraxx_download.php

This file has the following three lines of code on lines 1078-1080:

1078 $connection = connection_status ();
1079
1080 while (!feof ($fp) and (connection_status () == 0)) {


If you insert two lines between line 1078 and 1080 as follows

1078 $connection = connection_status ();
1079
1080 ob_end_clean();
1081 ob_start();
1082
1083 while (!feof ($fp) and (connection_status () == 0)) {


then the problem is gone!
Apparently it's a matter of clearing the output buffer before starting the file download.
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

GJC Web Design

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Milbo

Interesting. The problem is that somewhere your page does echo something. We tested the plugin with zips, actually you used the plugin to download the plugin :-)

But it is an interesting idea to add it to prevent this problem, But I wonder, this should be enough ob_end_clean();
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

innato

#8
My source is here http://php.net/manual/en/function.fread.php
See under User Contribution Note #4 by randym. He wrote:
QuoteConcerning [problems with UTF-8 and] downloading Zip files I found that simply adding 3 lines of code before starting the fread to the buffer for delivery in all browsers solved the problem.
In fact he adds three lines namely
Quoteob_end_clean();
    ob_start();
    header( 'Content-Type:' );

I was not sure about adding the last line because a content type header had already been defined a few lines earlier (in the plug-in I mean).

EDIT: The problem does not exist with JPG and not with PDF, meaning no extra chars are added (or removed).
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

Milbo

Interesting, which php version do you use? Reallly php5.6? I wonder, maybe it is a php bug.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

innato

Quote from: Milbo on October 10, 2016, 13:22:06 PM
Interesting, which php version do you use? Reallly php5.6? I wonder, maybe it is a php bug.
I use PHP 5.6.26 for sure
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2

innato

#11
Quote from: Milbo on October 10, 2016, 13:22:06 PM
VM3.0.18 on J3.6.5 and PHP 5.6.
With the latest isTraxx virtual download plugin version 2.4.14 the problem is still the same AND the solution is still the same (adding 2 lines of code, see my earlier post in this thread).
Regards
Rob

VM3.2.6 (enhanced) on J3.8.8 and PHP 7.1 or 7.2