Welcome to WebmasterWorld Guest from 18.207.136.184

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Get requested filename into env

need it for Content-Disposition

     
3:02 pm on May 20, 2007 (gmt 0)

New User

10+ Year Member

joined:May 2, 2005
posts:11
votes: 0


I'm using "Content-Disposition: attachment" to force a download dialog, but I also need to add the 'filename' parameter or else an IE6 bug is triggered. Without 'filename', if you click "Open" in IE6, the file is downloaded and then immediately deleted before it is opened.

So, I need the currently requested filename in an environment varoable so I can insert it into the header:


<Location /files>
SetEnv FILENAME filename # <-- need the actual filename here!
Header set Content-Disposition "attachment; filename=%{FILENAME}e"
</Location>

Is this possible?

Martin

4:14 pm on May 20, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


I usually set the MIME type for that filename extension to always force a download.

I assume that it is for ZIP or other such files?

8:41 pm on May 20, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


That variable is already defined:

Header set Content-Disposition "attachment; filename=%{REQUEST_FILENAME}"

I'm not sure if mod_headers will de-reference the variable. If it doesn't, then consider writing the header using a script.

You might want to take a look through the list of cgi variables if that one does not suit your needs.

Jim

3:11 am on May 21, 2007 (gmt 0)

New User

10+ Year Member

joined:May 2, 2005
posts:11
votes: 0


Here's the solution I ended up with:

SetEnvIf REQUEST_URI "/([^/]+)$" FILENAME=$1
Header set Content-Disposition "attachment; filename=\"%{FILENAME}e\"" env=FILENAME

It works fine, but unfortunately it didn't solve the problem I had with IE. The problem with IE was that if you clicked "Open", it would download the file but then delete it right before launching the external application (adobe pdf in this case)
This happened because I used mod_rewrite for mass vhosts:


UseCanonicalName Off
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)*(.+)$
RewriteRule ^/(.*)$ /var/www/vhosts/%2/$1

and mod_rewrite then adds "Vary: Host" to the response. IE would then mark the file as completely uncacheable (not just "Vary: Host") and delete it immediately after download.

I found a few workarounds here:
[iosart.com...]

Now I just use SERVER_NAME instead of HTTP_HOST, which works fine if UseCanonicalName is off. This way mod_rewrite won't understand that you're actually using the "Host" request header and won't add that "Vary: Host" header:


UseCanonicalName Off
RewriteEngine On
RewriteCond %{SERVER_NAME} ^(www.)*(.+)$
RewriteRule ^/(.*)$ /var/www/vhosts/%2/$1

Another solution is to simply remove the Vary response header with mod_headers.

Martin

4:07 am on May 21, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


This gets the first-half-of-2007 award for the most difficult IE workaround!

Glad you figured it out.

Jim

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members