abdelelbouhy Posted November 23, 2010 Share Posted November 23, 2010 hello guysi'm trying to set header('content-disposition:attachment;filename='.$file); and i placed the code even before the html tag but i got this errorWarning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test.php:2) in C:\xampp\htdocs\test.php on line 3but that only happend when i run it on apache if i run it in iis it worksplease help Link to comment Share on other sites More sharing options...
boen_robot Posted November 23, 2010 Share Posted November 23, 2010 If it's on line 3 this means that there's something on lines 1 and 2... if there's ANYTHING, even whitespace or a new line, before "<?php", then you're going to have this error. The very first characters in your PHP file need to be "<?php", and no "echo" and the like must occur before the headers are sent.The reason it works on IIS is that IIS delays output (which is a bad thing in many scenarios, though evidently, it does good in this one). Therefore, the header can be set, since the output hasn't started yet. Link to comment Share on other sites More sharing options...
abdelelbouhy Posted November 23, 2010 Author Share Posted November 23, 2010 If it's on line 3 this means that there's something on lines 1 and 2... if there's ANYTHING, even whitespace or a new line, before "<?php", then you're going to have this error. The very first characters in your PHP file need to be "<?php", and no "echo" and the like must occur before the headers are sent.The reason it works on IIS is that IIS delays output (which is a bad thing in many scenarios, though evidently, it does good in this one). Therefore, the header can be set, since the output hasn't started yet.you were right i put it before the <doctype>tag and it works but shouldn't be enough to place it before <html> tagthanx Link to comment Share on other sites More sharing options...
justsomeguy Posted November 23, 2010 Share Posted November 23, 2010 you were right i put it before the <doctype>tag and it works but shouldn't be enough to place it before <html> tagPHP doesn't know or care what a doctype or html tag is, or any other tag. It's all output to PHP. The rule is simple: anything outside of PHP tags is output that goes straight to the browser. PHP doesn't look at the output, it just sends it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.