EmmDub
asked on
Dynamic Content-Disposition filename in httpd.conf?
I've got a repository of files that are to be uploaded by users. In order to avoid filename collisions, we prefix the original filename with a unique ID. The problem happens when other users download the file; the ID is still in the filename. I know that the Content-Disposition response header field can suggest a filename, so I want to strip the ID from the start of the filename and use that.
The problem is that I don't know if I can do that with mod_headers in httpd.conf. It's easy enough to do with normal code, but I was hoping that mod_headers could evaluate an expression, or something along those lines.
The filenames are in this format: path/to/file/12345_origina lFilename. ext
The problem is that I don't know if I can do that with mod_headers in httpd.conf. It's easy enough to do with normal code, but I was hoping that mod_headers could evaluate an expression, or something along those lines.
The filenames are in this format: path/to/file/12345_origina
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The $ sign should be %, sorry
According to http://httpd.apache.org/docs/2.0/mod/mod_headers.html#header it should be valid
RewriteEngine On
RewriteRule ^([0-9]+)_(.+) - [E=realname:$2]
Header onsuccess set Content-Disposition "ATTACHMENT; FILENAME=\"%{realname}\"" env=realname
According to http://httpd.apache.org/docs/2.0/mod/mod_headers.html#header it should be valid
RewriteEngine On
RewriteRule ^([0-9]+)_(.+) - [E=realname:$2]
Header onsuccess set Content-Disposition "ATTACHMENT; FILENAME=\"%{realname}\"" env=realname
ASKER
After banging my head against the documentation for a while, I finally looked at the version of apache we're using. It's apache1, not apache2, which explains why it was complaining about the syntax of the Header directive, and explains why the environment variable wasn't being evaluated. The rewrite rule is working perfectly, but I still can't get the value into the header. Any ideas? If it can't be done, I'll have to look into doing this in code.
ASKER
Points bumped up.
1.3 documentation says nothing about variable substitution. So maybe it's impossible.
The only thing that comes to my mind is modules processing order. Maybe mod_header is processed before mod_rewrite. To get otherwise order, You need to make sure that mod_header is loaded before mod_rewrite, as modules are organized in stack manner.
The only thing that comes to my mind is modules processing order. Maybe mod_header is processed before mod_rewrite. To get otherwise order, You need to make sure that mod_header is loaded before mod_rewrite, as modules are organized in stack manner.
ASKER
Thanks for your help. I'll accept your first comment on Monday if nobody else responds, since it appears to be the right answer for apache2 users. I'll give you a split if somebody comes up with an apache1 solution.
ASKER
Header onsuccess set Content-Disposition "ATTACHMENT; FILENAME=\"${realname}\"" env=realname
and apache came back with:
Header takes two or three arguments, an action, header and value
which doesn't jive with the documentation. I took out "onsuccess" and "env=realname" and the Save As dialog started popping up, but the filename is just a dollar sign. Any ideas?