Page 1 of 1

Auto Download issues....

Posted: Tue Mar 09, 2010 6:30 am
by MiniMonty
Hi all,

I'm trying to trigger an auto download of a .zip file which I can do with this code

Code: Select all

 
    $filename = "blahblah/bleetbleet.zip";
    header("Pragma: public"); // required
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false); // required for certain browsers 
    header("Content-Type: application/x-zip");
    // change, added quotes to allow spaces in filenames, by Rajkumar Singh
    header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($filename));
    readfile("$filename");  
    exit();
 

Trouble is wherever I place it I get errors about cannot modify headers etc.,

How can I display a page with text and graphics which also triggers an auto download
of the zip file ?

Best wishes
Monty

Re: Auto Download issues....

Posted: Tue Mar 09, 2010 8:01 am
by davex
Hi,

That error usually indicates that something has been output first. You say wherever you put it but I'm guessing that there is an include() or something else above?

If your entire page just has the php tag and then that code all should be well.

If you are including any files then it will be whitespace in them - I suggest you have a look at output buffering using ob_start() as the very first line in the file before any includes and then ob_end_flush just before your header output.

Cheers,

Dave.