Offering Zip downloads

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chetanmadaan
Forum Newbie
Posts: 6
Joined: Fri Jan 16, 2009 10:41 pm

Offering Zip downloads

Post 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,
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Offering Zip downloads

Post 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);
(#10850)
chetanmadaan
Forum Newbie
Posts: 6
Joined: Fri Jan 16, 2009 10:41 pm

Re: Offering Zip downloads

Post by chetanmadaan »

I just copied it from StackOverflow.

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

Thanks for the tip though.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Offering Zip downloads

Post by Christopher »

Make sure it is $filepath.$file and not $filepath.'/'.$file.
(#10850)
chetanmadaan
Forum Newbie
Posts: 6
Joined: Fri Jan 16, 2009 10:41 pm

Re: Offering Zip downloads

Post 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!!!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Offering Zip downloads

Post 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!
(#10850)
Post Reply