Page 1 of 1

Offering Zip downloads

Posted: Mon Jan 04, 2016 12:17 pm
by chetanmadaan
I am using a simple PHP script to download downloads and then offer a zip file.

As soon as the zip is parsed through the PHP... unique hash of zip changes and it can't be extract using the unzip function PHP.

although, it works fine with windows to extract it... but the hash changes.

I am using the following headers... Anything i can do to fix this.

Code: Select all

	header("Content-type: application/zip");
	header("Content-Disposition: attachment; filename=\"".$file."\"");
	header("Content-Length: ".filesize($filepath.$file));
	ob_end_flush();
$filepath and $file containts the physical path of the file.

Any tips?

Thank you,

Re: Offering Zip downloads

Posted: Mon Jan 04, 2016 5:23 pm
by Christopher
Why are you using ob_end_flush()? Won't that gather any stray characters in the output buffer? Shouldn't it just be:

Code: Select all

	header("Content-type: application/zip");
	header("Content-Disposition: attachment; filename=\"".$file."\"");
	header("Content-Length: ".filesize($filepath.$file));
	readfile($filepath.$file);

Re: Offering Zip downloads

Posted: Mon Jan 04, 2016 5:47 pm
by chetanmadaan
I just copied it from StackOverflow.

I will give this a try and see if it works.

Thanks for the tip though.

Re: Offering Zip downloads

Posted: Tue Jan 05, 2016 2:06 pm
by Christopher
Make sure it is $filepath.$file and not $filepath.'/'.$file.

Re: Offering Zip downloads

Posted: Tue Jan 05, 2016 2:22 pm
by chetanmadaan
Worked... Perfectly fine.

The part about / between the $filepath and $file is only valid if i already don't have a trailing slash in the $filepath.

Either way,

THANK YOU!!!

Re: Offering Zip downloads

Posted: Tue Jan 05, 2016 4:43 pm
by Christopher
chetanmadaan wrote:The part about / between the $filepath and $file is only valid if i already don't have a trailing slash in the $filepath.
Sorry, I did not word my reply clearly. I meant if you do not have a trailing / then you need to add one between the path and filename. Glad you got it to work!