adrianTNT Posted November 17, 2008 Share Posted November 17, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/ Share on other sites More sharing options...
mapleleaf Posted November 17, 2008 Share Posted November 17, 2008 send the user to another page which checks the session data and header on to your zip download. The answer to your question I do not have but maybe a solution is enough Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/#findComment-691831 Share on other sites More sharing options...
adrianTNT Posted November 17, 2008 Author Share Posted November 17, 2008 That was my solution too, I thought there is another way around this. Otherwise, (as you said) I will have to separate session_start() from the file download. Any other ideas why that would happen ?! Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/#findComment-691832 Share on other sites More sharing options...
kenrbnsn Posted November 17, 2008 Share Posted November 17, 2008 Can you post more of you code? Just doing a <?php session_start(); ?> shouldn't corrupt the file. Ken Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/#findComment-691843 Share on other sites More sharing options...
adrianTNT Posted November 18, 2008 Author Share Posted November 18, 2008 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: Maybe I should add some encoding header information? Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/#findComment-692526 Share on other sites More sharing options...
kenrbnsn Posted November 18, 2008 Share Posted November 18, 2008 I bet there are error messages you're not seeing. Save the file and try opening it up with a text editor, you will probably see them. Ken Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/#findComment-692529 Share on other sites More sharing options...
adrianTNT Posted November 18, 2008 Author Share Posted November 18, 2008 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] Quote Link to comment https://forums.phpfreaks.com/topic/133021-session_start-interfering-with-zip-header/#findComment-692535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.