Jump to content

Force Download script problem


aniket_dj

Recommended Posts

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}%&öûêA­aÓ ª{"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.

 

Link to comment
https://forums.phpfreaks.com/topic/71382-force-download-script-problem/
Share on other sites

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.

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.