in reply to cgi saving files on client local disk

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.

  • Comment on Re: cgi saving files on client local disk