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.


In reply to Re^2: Download File using CGI by Joost
in thread Download File using CGI by MonkPaul

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.