0
votes

If any experienced guy ever encountered this kind of error like when my user downloads extensions zip file from my joomla site and tries to extract/open locally, they are getting invalid zip, central directory not found type of errors!.I zipped using winrar and problem comes up when they are not using winrar but other zip programs like winzip.I don't get why this should happen??

FYI i used virtuemart and spiral free download plugin for vm to make download available so is the extension zip file is not located under root folder of my site but in an inaccessible upper folder as joomla vm2 does.After the following tests i narrowed the problem down to the issues with joomla or virtuemart spiral free download plugin codes in the way it makes the zip download.

Test1 - to verify that putting zip outside of site root folder is not the problem, i placed the zip in site root folder and downloaded it by typing the address in browser, uninstalled local winrar zip program, and not getting any error when i open the zip by clicking.

Test2 -Then i created a joomla module and used same code as used by spiral free download plugin and download zip is now located in module folder(not outside of root folder) but when i downloaded the zip from module, i get same error as i wrote for which i am concerned about.

So precisely the problem is in joomla indirectly or in the code spiral free download plugin which prepares the extension product download zip for virtuemart of my joomla site.these codes are follows -

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename="".JFile::getName($media->file_url).""");
if (!readfile($media->file_url)) $output = jText::_('VMCUSTOM_SPIRAL_FREEDOWNLOAD_NO_FILE_FOUND');

I improved little bit here are these, but still zip problem persists -

header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename="".JFile::getName($media->file_url).""");
header("Content-Length: ".filesize($media->file_url));
if (!readfile($media->file_url)) $output = jText::_('VMCUSTOM_SPIRAL_FREEDOWNLOAD_NO_FILE_FOUND'); 

So are there any problems in these codes?

1
As i waited long but not getting replies from experts out there, so doing more tests i found that before those header declarations, if i add ob_end_clean(); ob_start(); then it seems working as i am testing locally.So should i put anything after/before headers declarations? plz reply with detail codes.dev-m

1 Answers

0
votes

Firstly (and this is just a side note), you should be using JText rather than jText.

Try using the following which has a few quotes changes

header("Content-Disposition: attachment; filename=".JFile::getName($media->file_url));

JFile::getName is also deprecated so depending on what version of Joomla you're using, try the following instead:

header("Content-Disposition: attachment; filename=".basename(strtolower($media->file_url)));