Okay here's what I'm up to. I have some files that are saved in a directory not accessable from the webserver. (The files come from email attachments but that's beside the point). They are saved there because I only want to allow access to them by the user the owns them. So I have a script that authenticates the user and then retrieves the file for them and prints it to their browser (i have the filetypes saved in a database). If the mime type can be displayed it shows up and if now it asks the user if they want to download the file.

This all works great except that when the file needs to be downloaded the browser defaults to the name of the script rather than the filename of the file. I tried sending the filename in the content header, for example a Word Document:

print "Content-type: application/msword; filename=mydoc.doc\n\n";

However the browser seemed to ignore this. Is there a header that can tell it what filename to use or do I need to find another solution?.

BTW I thought about htaccess but then the user would have to authenticate twice as they need to beable to retrieve the file from inside the web based email client I'm working on, so its not really a solution.

Thanks in advance
Chris

Lobster Aliens Are attacking the world!

In reply to How do I force a certain filename in the browser? by cfreak

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.