Force download file with PHP giving empty file?

This happened to be the issue. I have the file generated/exported in one page and then can be downloaded on a different page. Trouble is, the path to this file and the name of it can change based on the date.So, I was passing the name and directory in to the session.

Problem was I didn't include "session_start()" at the top of the script. Works like a charm now! – blandau Aug 25 '10 at 16:39.

Read the text file, then echo the text out after your header() calls. Here's how I have my csv download set up: //downloads an export of the user DB $csv = User::exportUsers(); header('Content-disposition: attachment; filename=userdb. Csv'); header('Content-type: text/csv'); echo $csv; Where exportUsers() creates the csv data.

You can easily just replace $csv with the contents of your text file, then echo it out. And as far as your text file, you can use file_get_contents() to get the contents of your file into a string. Then echo that string.

The benefit here is that you can var_dump($csv) to make sure it contains what you think it contains, before blaming the headers. – banzaimonkey Aug 25 '10 at 8:00.

Try setting the content length of the file: header('Content-Length: ' . Filesize($file)); Also, please have this in mind: file inclusion.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions