PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have created a routine that exports report data to a csv file and the end result is an empty CSV file upon download. I can run this code in the Zend and LAMPP locally and it works great. The CSV file is pipe-delimited but I don't think that is the problem. I starting to think that it has something to do with a setting on my server, Host Gator, which is using PHP 5.2.17. Does anyone know of any options in the PHP configuration that might prevent a download from working using the header() functions? Here is a shortened version of my code with all ob*, header*, and file operation statements. As I said before, this works fine locally on my laptop in either the Zend or XAMP/LAMPP server.
It looks like you are outputting a Content-Length of 0. If you want to output the correct content length, you would need to use ob_start(), ob_get_clean(), strlen then add Content-Length header then echo.
tr0gd0rr wrote:It looks like you are outputting a Content-Length of 0. If you want to output the correct content length, you would need to use ob_start(), ob_get_clean(), strlen then add Content-Length header then echo.
...unless the size of the $csvfilename file isn't zero, in which case the Content-Length will be whatever the length of the file is.
If you're outputting a file, Content-Length with filesize() and readfile() are all that you "need".
I have tried everything that both of you have said. I even tried using echo and print instead of fwrite and fputcsv, to no avail. At the point the download occurs, it should have at least the header record in it, which is not based on anything pulled from the database. Even if I just echo a simple string with text/plain, I get an empty file.