Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,195 members, 7,822,038 topics. Date: Thursday, 09 May 2024 at 03:25 AM

Facing Header Problem - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Facing Header Problem (693 Views)

Programming Challenge - Navigate Using Same Cache Header / Php Header() Function Error / Php Header() Function Error (2) (3) (4)

(1) (Reply)

Facing Header Problem by Nobody: 12:18am On Mar 29, 2013
Hi All,

I'm creating a website that creates a zip file and forces user to download of the created file.
I'm having trouble using the header to read the file correctly.

Below is my code:
(Toggle Plain Text)

$zipLocation = "./filesFolder/$pageName.zip";

if(file_exists($zipLocation))
$flag = ZipArchive::OVERWRITE;
else
$flag = ZipArchive::CREATE;

$zip = new ZipArchive();
$zip->open($zipLocation, $flag);

$zip->addFile("$htmlLocation","$pageName.html"wink;
$zip->addFile("$cssLocation","$pageName.css"wink;
$zip->addFile("$jsLocation","$pageName.js"wink;

$zip->close();
$zip = null;

print "zipped<br/>";
//header("location: $zipLocation"wink;

header("Cache-Control: must-revalidate"wink;
header("Content-type: application/force-download"wink;
header("Content-Transfer-Encoding: binary"wink;
header("Content-disposition: attachment; filename=$pageName.zip"wink;
readfile($zipLocation);

The zipfile gets created correctly but when the download dialog appears, the file size is wrong, and when it downloads it cannot be opened.

If I use the commented line it works correctly, but I would rather do it this way using the readfile.

Can any one tell the reason behind it?
Re: Facing Header Problem by Nobody: 10:33am On Apr 04, 2013
Set all headers before using print
Once you use print/echo/print_r etc. any header set thereafter is a joke

(1) (Reply)

Please I Need Some I Can Talk To For My Little Php Issue / Help With Php Update Function / Please I Need Help In FORTRAN PROGRAM

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 8
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.