RE: [PHP] Header's download
Hello Richard. I totally agree with you. And I have tried to comment this to my employer. But as a consultant, my short stay has one purpose. Make it work, and then leave us alone. We have employees who keep track of the spaghetti :-) This is a very good example, how not to design systems.. I will of course comment this in the code. Thanks for your comment. Regards Christian Fra: Richard Lynch [mailto:[EMAIL PROTECTED] Sendt: 1. desember 2004 22:06 Til: [EMAIL PROTECTED] Emne: Re: [PHP] Header's download Christian Johansson wrote: > Header("Content-Type: application/download"); > Header("Content-Disposition: attachment; filename=export.txt"); > > Then after this is done I know that I can write stuff to the file like > this: > > Echo "This will be a line in my file\n"; > > I am standing in a GUI containing frames. > > So I want to give an administrator the rights to choose what to export. > > My problem is that when I include the php file "download.php", the > HTML\JAVA code are written to the file. The root cause of this is that *somewhere* in your scripts and PHP and HTML, you are forcing PHP to send those headers and your HTML and JavaScript out before you send out the headers and/or the content. While output buffering may allow you to gather all that content, and then throw it away, and then you can send your download... Wouldn't it make more sense to re-structure your code so that none of that crap (HTML and JavaScript) is being parsed by PHP? What if someday you decide to do something more interesting in PHP in the code that does the HTML and JavaScript output? Your downloads will maybe stop working, or you'll be executing the PHP script, but not even realizing it, because all the HTML and JavaScript output is thrown away, so you never "see" it, so you don't remember it's there... This is going to take a bit more work than just throwing in an ob_start() and whatever you call to throw away the output buffer, but you'll have cleaner and more clear code in the end. Up to you, really, as you're probably the one that has to maintain it... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Header's download
Hello. I use: Header("Content-Type: application/download"); Header("Content-Disposition: attachment; filename=export.txt"); Then after this is done I know that I can write stuff to the file like this: Echo "This will be a line in my file\n"; I am standing in a GUI containing frames. So I want to give an administrator the rights to choose what to export. My problem is that when I include the php file "download.php", the HTML\JAVA code are written to the file. download.php are containing the headers. All the export data are written to the file, but also HTML\JAVA. How can I get around this problem? I would be very happy if someone has a solution. Regards Christian Johansson The solution: Use ob_clean()to emty the buffer, Before you use the headers: ob_clean(); Header("Content-Type: application/download"); Header("Content-Disposition: attachment; filename=export.txt"); http://no2.php.net/manual/en/function.ob-clean.php That's it! Regards Christian Johansson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Header's download
Hello. I use: Header("Content-Type: application/download"); Header("Content-Disposition: attachment; filename=export.txt"); Then after this is done I know that I can write stuff to the file like this: Echo "This will be a line in my file\n"; I am standing in a GUI containing frames. So I want to give an administrator the rights to choose what to export. My problem is that when I include the php file "download.php", the HTML\JAVA code are written to the file. download.php are containing the headers. All the export data are written to the file, but also HTML\JAVA. How can I get around this problem? I would be very happy if someone has a solution. Regards Christian Johansson
[PHP] Problems with headers and downloading file
Hello. I have a problem with downloads with the use of header() I have this code at the start at the download site: Header("Content-Type: application/download"); Header("Content-Disposition: attachment; filename=export.txt"); My problem is that the file which is downloaded contains HTML code which I don't need, and don't want to have there. Is there some way to take control on what should be written to the file? I am almost there, I have all the data I want do generate on the file, but in the start of the file HTML code are written. Anyone who can help me? I can't store a file on the server, and then download it, because of some government rules. Regards Christian Johansson