I have no clue how I could do that, but I believe there should be a way other than fwrite() it into a file and print a link into the browser?

I donīt mind if the user gets the normal download dialog displayed, where he can choose where he wants to save the file, all I need is a way to send data as file, without having an actual file on the server.

Could anyone give me a hint?
Thanks in advance.

mlseim

03-11-2010, 10:29 PM

What is the filetype?
Is $putinfile a filename or some text ... or what is it?

The output streaming would be good if you potentially have a LOT of row data to output, and instead of gobbing up a ton of memory in one fell swoop, you could stream it to the client as it is retrieved.

Goldfish

03-11-2010, 10:41 PM

I have to try that.
Thanks

Edit:
The good news: It works, the user receives the file.
The bad news: The browser doesnīt print the rest of the page, but remains on the previous page.

So how can I print the page the browser should display after the file has been sent, without the user has to click somewhere?

This will successfully send a file named "whatever.txt" with the content "xyz" to the user, but unfortunately it wonīt write the HTML part to the users browser.

kbluhm

03-11-2010, 11:17 PM

No, the content must be streamed from it's own file in this case, with no output afterward. I alluded to that by placing exit() at the end of each example. ;)

Goldfish

03-11-2010, 11:26 PM

Ah well, I figured that by now, so I guess I have to work around it.
Thanks anyway, very fast, very helpful.

mlseim

03-11-2010, 11:28 PM

So what's the purpose of "the attachment".
Is there a reason the output couldn't be displayed on the page that is being displayed?
So instead of the header, you have a PHP "include" on the page they are viewing?

I can't figure-out what the purpose is ... what you're doing.

Goldfish

03-11-2010, 11:46 PM

The purpose is a complex calculation of tons of numbers, where I want to display a summary of the result in the users browser, while at same time sending him a detailed version as file.
The reason why I donīt display both in the browser is, the file can easily reach 50 pages of text, while the summary fits into 20 lines.

Side note: Thanks again to kbluhm for the streaming version, I really can use that one.

As an example, imagine you want to create statistics about visitors on your homepage.

The summary would show:
The site has x members.
In last x days y users have logged in.
The most users online were x at date/time.