Neither the server nor your CGI application have access to the client except in their ability to return an HTTP response to it. Furthermore, an HTTP response can only contain one document. (I'm ignoring multi-part documents and archives since the browser would still take those to be one document.) For example, if an HTML page is returned, nothing else can be returned.

Let's look at the simple case first: There is no need to return an HTML page. Then you can just return the file you want to save as the body of the response, and tell the browser that it should be saved instead of displayed by using the appropriate Content-Disposition header. The user will be prompted where to save the document. This is inescapable because web sites must not have arbitrary access to your hard drive for obvious security reasons.

The next case in ascending complexity is one HTML page to display and one document to save. You can do that by returning the HTML and include inside of it ab HTTP redirect back to your script (presumably with extra parameters). This second call to your script is just the simple case above. You can look at the response you get from the download page of your favorite application for an example.

The most complex case is when there are multiple documents to save in addition to the HTML page. You'd have to use frames or JavaScript to initiate multiple call back to your CGI script (again, with different parameters to indicate which file to save). This won't be very usable since the user will have to specify the location of each file. You'd be much better off returning an archive or an installer.


In reply to Re: cgi saving files on client local disk by ikegami
in thread cgi saving files on client local disk by przemek88

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.