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: