Zen Cart Logo
Forums / Bug Reports / [Done v1.3.9] Download product issue v1.3.6

[Done v1.3.9] Download product issue v1.3.6

Locked

Views: 1,653

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
11 Jun 2008, 6:35 PM
#1
evilmoocow avatar

evilmoocow

New Zenner

Join Date:
Feb 2008
Posts:
2
Plugin Contributions:
0

[Done v1.3.9] Download product issue v1.3.6

Hi,

I am using an old version of ZenCart (1.3.6) and when I have files to download does it do some wierd stuff. I am using streaming.

It download the file, but when I open the file in a Hex editor have it addet a space (20 hex) in the beginning and removed the last letter of the file.

"%PDF...%%EOF" get turned into " %PDF...%%EO". PDF files dont care about this, but the ZIP files doesnt like it.

Any idea how to get the "correct" steam downloaded?

Code:

header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: Application/octet-stream");
header("Content-disposition: attachment; filename=" . $downloads->fields['orders_products_filename']);
$zv_filesize = filesize(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);

if (DOWNLOAD_BY_REDIRECT == 'true') {
  // This will work only on Unix/Linux hosts
  zen_unlink_temp_dir(DIR_FS_DOWNLOAD_PUBLIC);
  $tempdir = zen_random_name();
  umask(0000);
  mkdir(DIR_FS_DOWNLOAD_PUBLIC . $tempdir, 0777);
  $download_link = str_replace(array('/','\\'),'_',$downloads->fields['orders_products_filename']);
  $link_create_status = symlink(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'], DIR_FS_DOWNLOAD_PUBLIC . $tempdir . '/' . $download_link);
  $zco_notifier->notify('NOTIFY_DOWNLOAD_VIA_SYMLINK___BEGINS');

  if ($link_create_status==true) zen_redirect(DIR_WS_DOWNLOAD_PUBLIC . $tempdir . '/' . $download_link);
}

if (DOWNLOAD_BY_REDIRECT != 'true' or $link_create_status==false ) {
  // not downloading by redirect; instead, we stream it to the browser.  This happens if the symlink couldn't happen, or if set as default in Admin
  if (DOWNLOAD_IN_CHUNKS != 'true') {
    // This will work on all systems, but will need considerable resources
    header("Content-Length: " . $zv_filesize);
    $zco_notifier->notify('NOTIFY_DOWNLOAD_WITHOUT_REDIRECT___COMPLETED');
    readfile(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename']);
  } else {
    // loop with fread($fp, xxxx) to allow streaming in chunk sizes below the PHP memory_limit
    header("Content-Length: " . $zv_filesize);
    flush();
    $handle = fopen(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'], "rb");
    while (!feof($handle)) {
      echo(fread($handle, 4096));
      flush();
    }
    fclose($handle);
    $zco_notifier->notify('NOTIFY_DOWNLOAD_WITHOUT_REDIRECT_VIA_CHUNKS___COMPLETED');
  }
}

Dont know if the issue is that the file is saved in a wrong format or something, but have tried ACSII and UTF-8 without luck.

Have tryed many creative ideas, but without luck... :(

HELP :cry:

12 Jun 2008, 4:55 AM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: [Done v1.3.9] Download product issue v1.3.6

Since v1.3.6 is no longer officially supported, and there have been many improvements since then, perhaps the best test would be to install 1.3.8 and see if the problem follows, or if it maybe changes somewhat.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Jun 2008, 8:38 AM
#3
evilmoocow avatar

evilmoocow

New Zenner

Join Date:
Feb 2008
Posts:
2
Plugin Contributions:
0

Re: [Done v1.3.9] Download product issue v1.3.6

That part of the code is more or less the same, so an upgrade wont fix it (I have been looking in the code for the newest version).

I guess the issue is more likely maybe not something to do with Zencart itself, but more file-encoding or something. the function should work according to all PHP ppl, but somehow does it add the space in the beginning and remove the last letter.

Have found a funny work around that fixes the Zip file, but destroies the PDF file.

$handle = fopen(DIR_FS_DOWNLOAD . $downloads->fields['orders_products_filename'], "rb");
fread($handle, 1)
while (!feof($handle)) {
  echo(fread($handle, 4096));
  flush();
} 

fread($handle, 1) makes the white space come again, but removes the first letter of the file instead of the last.

"%PDF...%%EOF" get turned into " PDF...%%EOF"