in reply to Re: Download File using CGI
in thread Download File using CGI

You're still printing a html header and HTML content before printing the header for the file's content.

As I said before; you can't mix multiple files in one response - the HTML page is one of those files - the other is the file you want people to download.

You have several options:

You print the file's content in the HTML (without the headers, and remember to use escapeHTML() to escape any HTML tags in the file) and people will have to cut & paste to save the content.

You print the correct headers and the file's content and nothing else and the file can be saved with the correct name when that script is called (if the browser supports the content-disposition header)

You just link to a static file on the server using a normal <a> tag (by far the easiest, and most efficient).

As for how to pass the filename (dangerous: you don't want just any file to be downloadable) - see Ovid's CGI course.