CGI dynamic naming of file download

This is a discussion on CGI dynamic naming of file download within the A Brief History of Cprogramming.com forums, part of the Community Boards category; What I'm wanting to do, and currently searching the web for, is to generate a binary file on-the-fly and also, ...

  1. #1
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065

    CGI dynamic naming of file download

    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

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,403
    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?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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:
    Code:
    <a href="mycgiscript" name="thenamewiththe.ext">text</a>

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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:
    Quote Originally Posted by http://www.htmlquick.com/reference/tags/a.html
    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.
    Last edited by Kennedy; 04-18-2008 at 01:17 PM.

  5. #5
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065

    Wink

    Found the solution:

    Before streaming the data, one line is always required.
    Code:
    Content-Type: binary
    The next line is recommended unless it is too difficult to get
    Code:
    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
    Code:
    Content-Disposition: :attachment;filename=<the filename you want>
    So, there we have the complete answer to my question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21