aniket_dj Posted October 1, 2007 Share Posted October 1, 2007 Hi guys, I am running an Apache Server and using PHP to force download a zip file to the client. I have made sure that the zip file is present when running the following script $file = $_SESSION["download_file"]; // We'll be outputting a ZIP header('Content-type: application/zip'); // It will be called wert.zip header('Content-Disposition: attachment; filename="wert.zip"'); // The ZIP source is in $file [$file is portww.zip] readfile($file); The error I get for this is Warning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/bye.php: in /opt/lampp/htdocs/bye.php on line 13 Warning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/bye.php: in /opt/lampp/htdocs/bye.php on line 16 PK����_A7Á݃$®��=����dummy_55_bcell.inUT �®G—GUx�þÿþÿ”ÑNƒ0†ï}Š>›D½$¬š&–Q“éMÓÁq4B»@§áímçf ÙÖhÊÿöœÿ”(X`”,qH‚òŽçh“BQ j–PÑ”»\1Ø C!x$_€¢xµ0Ÿ'·“vø‡™‡f³1¼„RUÍe¼Èܘg'>xÆe‰É�yví&|£1 Ö$AB~@ª!Ci£ÛBU iÎ᪶J³Z• s!·.)^/W8I^‡+LM¡þâlº³µNqÑh‘þWº¥»‚×%ï|¨÷RèNmµ (f]®†‹#ïì86_¢Ú×hÃk`µæÚZ„”ÄÑE¼’À”¼ŽÕßêz6¯àú?Ô¾rÁ”,Ž+LY¤F¯y2ý„îlu}ÝùhOt6þrÞCkËýÔ>‡Ñ–É€gÐo¹é¤ç–«xþb6'ØåŸuß]…þRèŠËZha¿ØþáguÀ0~VŒàçõÁp€¡V0Ŧ˜D#ŽožÛÒ#q[YKGÛ¡ºKsH?Oiï´+lBŒK-6*kŽ}M‡R:‰íøŒ¬§úªüÌ™×PK����5`A7ö|KºÍ���Õ����dummy_55_ebvirus.inUT �æG¯GUx�þÿþÿQÑ ‚0}÷+î„ô¾tÅHgä‚èeÌZ$ÈNþ>-Wâ^Îa÷žs¹çRa˜oÃȴΊʀC(a…`DžÕRa$7¥(%Ðx5wâ>ž÷¢ ŸMÁAKLOÈ7%œ„!†ùãïÖq‚ƒ¾aŸdžƒY-ÐöÙwµV’kea¨ª¼è¶½ƒÁªs!ïcžd¨ò¤«¢í·8Tפ۰9ªÌR}¼¾ßùŒÄôoJݾã<íÖô#Nz#ž”R(ê>hÎ[òN}C"(>ç)WÞ(âQe–[[˜‹,#lÈ»2§VèñX¡H}%&öûêAaÓ ª{"tý goº/š£äèè=¯Ã%wÏ(^\ Ó½ £‰£Ø߸ÇÍÕŽ—)¢u°|á\œÿãW±v@gež˜é,?÷`¥Ø°¥ßÚ¸œ,ÚÛPK����_A7Á݃$®��=��� ��������¤����dummy_55_bcell.inUT�®GUx��PK����5`A7ö|KºÍ���Õ��� ��������¤ò��dummy_55_ebvirus.inUT�æGUx��PK����_A7½©rÛN���—���� ��������¤��dummy_55_tissue.inUT�®GUx��PK����_A75·V½É���‚��� ��������¤˜��dummy_55_mesh.inUT�®GUx��PK������2��¤���� Could you tell me where am I going wrong. Do I need to reset anything so that the headers are sent fresh? Also do tell me whether there is another different [elegant] way of doing this? Thanks. ~Aniket. Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/ Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 Warning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/bye.php: in /opt/lampp/htdocs/bye.php on line 13 what is on line 8 of /opt/lampp/htdocs/bye.php? Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359223 Share on other sites More sharing options...
d.shankar Posted October 1, 2007 Share Posted October 1, 2007 Try this $file = $_SESSION["download_file"]; header('Content-type: application/zip'); header('Content-Disposition: attachment; filename=".$file."'); readfile($file); Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359229 Share on other sites More sharing options...
Orio Posted October 1, 2007 Share Posted October 1, 2007 The script I found here helped me alot, and it works great. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359232 Share on other sites More sharing options...
aniket_dj Posted October 1, 2007 Author Share Posted October 1, 2007 Hi, In trying to do a 'lot' of PHP, I forgot that this can be done much more elegantly thru HTML echo "<a href=".$file.">Click here to Download</a>"; The only drawback of this method is there needs to be an additional click. ~Aniket. Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359263 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 You could do it without the extra click via META refresh or Javascript as well. Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359269 Share on other sites More sharing options...
Orio Posted October 1, 2007 Share Posted October 1, 2007 Hi, In trying to do a 'lot' of PHP, I forgot that this can be done much more elegantly thru HTML echo "<a href=".$file.">Click here to Download</a>"; The only drawback of this method is there needs to be an additional click. ~Aniket. Yeah, try that when you want to let someone download a jpg/gif/pdf/mp3/doc etc'. It will simply open them, not download them. That's why you need force downloading... Orio. Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359285 Share on other sites More sharing options...
MadTechie Posted October 1, 2007 Share Posted October 1, 2007 Echo d.shankar, <--is correct @aniket_dj, please read the pinned topic called headers or try opening the download script via a new window ie <a href="download.php" target="_blank">download</a> Quote Link to comment https://forums.phpfreaks.com/topic/71382-force-download-script-problem/#findComment-359290 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.