Jump to content

session_start() interfering with "zip" header.


adrianTNT

Recommended Posts

Hello.

I have a code that should prompt for a zip file download.

 

header("Content-Type: application/zip");
header('Content-length:'.filesize('zips/'.$_REQUEST['listing_id'].'.zip'));
readfile('blabla.zip');

 

It works OK but the problem is that I have to add session_start() right before that code, to check some user properties.

When I do this I get "corrupted zip file" error in browser.

 

Is it wrong to add session_start() with zip header info? Maybe there is some known issue?

Thank you.

Can you post more of you code? ... session_start(); shouldn't corrupt the file.

I simplified it as much as I could removing db queries, this gives an error:

 

if(isset($_REQUEST['file_to_get']) and $_REQUEST['file_to_get']!=''){
session_start();
header("Content-Type: application/zip");
header('Content-length:'.filesize('temp_zips/'.$_REQUEST['file_to_get']));
header("Content-Disposition: attachment; filename=".$_REQUEST['file_to_get']);
readfile('temp_zips/'.$_REQUEST['file_to_get']);
unlink('temp_zips/'.$_REQUEST['file_to_get']);
exit;
}
?>

 

Just adding session_start() there shows me this error:

 

1387_600x400.jpg

 

Maybe I should add some encoding header information?

I looked with notepad and first characters appear to be pczip something (the library that creates the zip) but I dont see any errors.

I attached that zip if you want to look but I think there is nothing helpfull.

 

This happens in InternetExplorer only, if I chose directly "open" at download prompt.

If I chose "save" then after download completed I chose "open" it works fine.

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.