Author Topic: SOLVED: ZIP file download fails  (Read 1817 times)

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
SOLVED: ZIP file download fails
« on: October 05, 2016, 20:24:00 pm »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9024
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: ZIP file download fails
« Reply #1 on: October 05, 2016, 23:55:42 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: ZIP file download fails
« Reply #2 on: October 06, 2016, 10:25:55 am »
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9024
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: ZIP file download fails
« Reply #3 on: October 06, 2016, 13:39:22 pm »
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 http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: ZIP file download fails
« Reply #4 on: October 06, 2016, 16:45:02 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

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: ZIP file download fails
« Reply #5 on: October 06, 2016, 21:23:36 pm »
= 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:

Code: [Select]
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

Code: [Select]
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

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 9024
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.4.2
Re: SOLVED: ZIP file download fails
« Reply #6 on: October 06, 2016, 23:13:12 pm »
Gave Max a heads up..  thanks
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 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
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9911
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: SOLVED: ZIP file download fails
« Reply #7 on: October 06, 2016, 23:41:31 pm »
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();
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: SOLVED: ZIP file download fails
« Reply #8 on: October 07, 2016, 10:26:27 am »
My source is here http://php.net/manual/en/function.fread.php
See under User Contribution Note #4 by randym. He wrote:
Quote
Concerning [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
Quote
    ob_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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9911
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: SOLVED: ZIP file download fails
« Reply #9 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 should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

innato

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: SOLVED: ZIP file download fails
« Reply #10 on: October 10, 2016, 22:44:25 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

  • Jr. Member
  • **
  • Posts: 52
  • Newby to this forum
  • VirtueMart Version: VM 3 on Joomla! 3
Re: SOLVED: ZIP file download fails
« Reply #11 on: March 06, 2017, 12:23:40 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