Page 1 of 1

Serving a dynamically created file, plus extra HTML?

Posted: Thu Apr 15, 2010 1:33 am
by tony311
I have a script that takes some GET variables and creates a KML file for Google Earth. The headers are set such that as soon as the page loads, the KML is echoed, the browser downloads it, and Google Earth opens it automatically. However, I can't seem to do anything after that. What I want to do is echo a line of Javascript that closes the tab/window automatically, since the page itself is useless other than serving the KML. All you end up with is a blank window.

If I try to add code after the KML is echoed, it adds that to the KML, which causes Google Earth to complain about junk data. I tried using flush(), but that didn't work. I guess I'm trying to set it up like a lot of download pages you see; the file download popup is raised, but there's still HTML echoed to the window (obviously, since if there weren't, it would just be a blank page). Anyone know how to do that?

Note: If the Content-Disposition header is set to inline, the file downloads in the background automatically. If it's set to attachment, it always raises the download dialog ("What would you like to do with this file?"). Since this all needs to be as streamlined as possible, a download confirmation dialog is not acceptable.

Thanks for the help in advance.

Re: Serving a dynamically created file, plus extra HTML?

Posted: Thu Apr 15, 2010 3:14 am
by Bind
You either have to put up with the open window OR have a download dialog with the forced download. Either way the user has to have some sort of notification your website/files are interacting with their computer/software.

Would you want stealth downloads forced by a website interacting with, installing in, or firing off applications on your computer ?

for obvious security reasons, I would think not.

the only way to get by this would be for you to develop some sort of 3rd party stand-alone application in which you can stealth stream the file through to interract with GE, AND convince you visitors to use it.

Re: Serving a dynamically created file, plus extra HTML?

Posted: Thu Apr 15, 2010 3:20 am
by tony311
No, the download already runs in the background (although not by default, you have to choose a program to open it with the first time and tell the browser to repeat the same action for all files of that type). I just need a way to echo some HTML after the file is created and echoed by PHP.

Edit: to clarify about the content disposition, inline allows the browser to silently download it in the background, as long as the user has told it to perform the same action automatically, whereas attachment seems to raise the download dialog every time, regardless of your settings for that filetype. That's why I need it to use inline rather than attachment if possible.