You could deliver the file's content "dynamically", and do explicit line endings conversions yourself as required. For example, you could have a generic CGI script, which takes the file name as parameter (e.g. deliver_plain_text.pl?file=123.inp). The CGI would read the file, convert the line endings (s/\n/\r\n/), and write the result to stdout (which apache sends to the browser, as usual). If you don't want to have deliver_plain_text.pl appear in the URL, you could use mod_rewrite to do some rewriting magic for you...   Also, you might want to apply some heuristics to detect whether the client actually is a Windows machine (e.g. by inspecting the User-Agent header), and only do line ending translations in that case.

Alternatively, you could try to add an Apache output filter for the appropriate type of files, using mod_mime's AddOutputFilter. I'm not aware of a ready-to-use apache filter for just that purpose, but - if performance is not a primary issue - you could use mod_ext_filter to pipe the content through a simple external program, which does s/\n/\r\n/ ...


In reply to Re: Downloading a Text file from a Unix server (Apace) using CGI by almut
in thread Downloading a Text file from a Unix server (Apace) using CGI by stumbler

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.