-
Report download
Hello!
I need to generate online reports from a mysql db. Now i want to have a option which will be...
to generate a report fro the db...and download it as a text file...how can this be achieved ? I need to download the file without creating it on the server. Means i do not want to first create a text file on server and then download it...i just want to starightly download it...!
Please help!
Thanks!
-
AFAIK, you cannot do this. There must be a version of the file on the server that will be served to the browser. You cannot feed something like a buffer to the user.
The easiest thing would be just to create the file in text file. But each time the page is executed to download the file, have part of your script check for files older than some x time, and delete them. That way your server doesn't fill up and you don't have to write a special app to do this randomly.
-
Hi Ober!
You are wrong at this thing my friend. This is possible and just needs some header manipulation...! I created a script like this and now i forgot how i did it...lemme check it out...and i will post here if i find it...!
Thanks!
-
Ok... no need to be a dick about it. If you already knew how to do it, you shouldn't be posting here in the first place.
-
hi
i jist forgot it...as i made that with help also...but now i don't even remember how i did it...that is why i posted it... :(
thanks!
-
You need to serve a few headers.
Content-type: text/plain
Content-disposition: attachment; report.txt
I think that's it. Then the output of your PHP script ought to be treated as a text file that gets downloaded.
-
Thanks! Do i have to do it like this:
header "Content-type: text/plain
Content-disposition: attachment; report.txt";
echo $somevar;
and this will get downloaded as text file right ?
-
header('Content-type: text/plain');
header('Content-disposition: attachment; report.txt');
echo $content;
That should do it.
-