PDA

View Full Version : CGI dynamic naming of file download



Kennedy
04-18-2008, 10:20 AM
What I'm wanting to do, and currently searching the web for, is to generate a binary file on-the-fly and also, somehow, tell the client the "real" name of the file, such that the client user doesn't have to think -- any time the user has to think, this is bad -- my opinion.

I was looking through the Content- tags and have found the one that allows me to tell the client the size of the stream being sent, but I still need to provide it a filename.

Any ideas?

Thanks,
Kennedy

Mario F.
04-18-2008, 10:55 AM
Sorry Kennedy, not sure if I understood your question?
You want to move content upstream that gets generated on the fly without a request from the client?

Kennedy
04-18-2008, 12:44 PM
I think I may have figured it out, but I don't know yet. The object is a collection of files, of all the same type, that I will cat into one "file", however, I cannot cat this to a real file without possibly screwing myself if the filesystem is too full already. The goal is to have a link that on-the-fly generates the "file" download. The thing to do I believe is this:


<a href="mycgiscript" name="thenamewiththe.ext">text</a>

Kennedy
04-18-2008, 01:11 PM
Nope, didn't work. What is the name directive for? Is there a way that I can augment the filename of the download and still run my script?

EDIT: The name directive:
Defines a unique name for the element so it can be located later. It's used to set bookmarks on a page. It's recommended to use the "id" attribute instead because of its compatibility with XHTML code.

Kennedy
04-18-2008, 01:33 PM
Found the solution:

Before streaming the data, one line is always required.
Content-Type: binary The next line is recommended unless it is too difficult to get
Content-Length: <the length of the download>The next thing I found makes the download box pop-up and gives a default name for the download
Content-Disposition: :attachment;filename=<the filename you want>

So, there we have the complete answer to my question.