HTTP header for custom zip download module

BSLFE

Joined: 2008-08-04
Posts: 13
Posted: Wed, 2009-03-11 18:47

Hi to all,

I'm new to G2 programming and I have a problem. :) I've searched on this site and on google but couldn't find an answer.

What I'm trying to do is to write a simple module that will check whether an album has an accompanying zip file in the album folder (zip filename = Albumname + ".zip") and if doesn't create the zip file. Then click a button and the zip file will be downloaded. Most of it I have already done by reading the doc here and looking at other models. However, I'm stuck with the downloading part. I have looked at the "DownloadItem.inc" file and the zipcart module and have either re-done or simply copied & pasted the necessary code parts. My problem is that the HTTP header for the "content-type" will not change from "plain/html" to "application/zip" and thus the browser will not interpret the stream as a binary file it's supposed to download. I have tried both the delegate and the redirect method but didn't succeed. I'd post my code here but I've simply copied the "sendFile()" method from DownloadItem class and I'm sure my problem starts before that.

Is there anyone who understands my problem and can help me?

Thanks in advance!

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2009-03-11 20:28

Why reinvent the wheel?

http://codex.gallery2.org/Gallery2:Modules:zipcart
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
BSLFE

Joined: 2008-08-04
Posts: 13
Posted: Wed, 2009-03-11 21:46

Good question but I think zipcart is a little bit too complicated and I'd like to have per-Album zip download and not per "cart".

I'd appreciate any help!

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Wed, 2009-03-11 22:13

You should post your code as an attachment; you can't expect other people to recreate precisely what you've done from your brief description, and tiny differences can make all the difference.

 
BSLFE

Joined: 2008-08-04
Posts: 13
Posted: Thu, 2009-03-12 19:25

Ok I've attached all my source files (and had to rename them to *.txt but of course they are *.inc on my computer) and hope someone can locate my problem. As I previously said much of my code was copied&pasted so don't be surprised if you recognise it :)

Thx for your help!

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Thu, 2009-03-12 19:37

Probably easiest just to zip the entire module folder and post that...

 
BSLFE

Joined: 2008-08-04
Posts: 13
Posted: Thu, 2009-03-12 20:22

Here you go... :)

 
BSLFE

Joined: 2008-08-04
Posts: 13
Posted: Wed, 2009-03-18 17:21

Can anyone help me with this problem?

 
BSLFE

Joined: 2008-08-04
Posts: 13
Posted: Mon, 2009-04-13 13:24

I have found the solution for this problem: 2 newlines at the end will prevent phpVm->header() from working!

more here: http://gallery.menalto.com/node/87004