文章标签 » apache

一段指定附件下载名的apache配置

继续优化

SetEnvIf Request_URI "\/SAVE\/(.*)$" save_file_name="$1"
SetEnvIf Request_URI "\.(jpg|jpeg|png|gif|bmp)$" is_image_file
#除了图片,其他文件直接访问均提示下载,防止上传了js,css,html等不应该被浏览器加载的文件
Header set Content-Disposition attachment env=!is_image_file
Header set Content-Disposition "attachment; filename=%{save_file_name}e" env=save_file_name
RewriteEngine On
RewriteRule ^/(.*)\/SAVE\/.*$ /$1 [L]

——————————————————-
优化一下~

SetEnvIf Request_URI "\/SAVE\/(.*)$" save_file_name="$1"
Header set Content-Disposition "attachment; filename=%{save_file_name}e" env=save_file_name
RewriteEngine On
RewriteRule ^/(.*)\/SAVE\/.*$ /$1 [L]

只需要访问 : ….5_1300238850.jpg/SAVE/我的图片.jpg 就可以了,ie下文件名后面竟然也不会出现“[1]”了~
—————————————-

SetEnvIf Request_URI "_DOWN_NAME_(.*)_DOWN_EXT_(.*)$" save_file_name="$1.$2"
#下面这种ie下有问题
#SetEnvIf Request_URI "_DOWN_NAME_(.*)$" save_file_name="$1"
Header set Content-Disposition "attachment; filename=%{save_file_name}e" env=save_file_name
RewriteEngine On
RewriteRule ^/(.*)\._DOWN_NAME_.*$ /$1 [L]

实现的效果:
假设一个附件上传后的地址是:
http://foo.com/03/21/1bc5b77f3e50b7fbe12c792ee438da45_1300688708.jpg

如果想要指定下载名,则访问:
http://foo.com/03/21/1bc5b77f3e50b7fbe12c792ee438da45_1300688708.jpg._DOWN_NAME_我的图片_DOWN_EXT_jpg

ie下的效果:
screenshot_127.png

chrome下的效果:
screenshot_128.png

FF下的效果,很杯具:
screenshot_129.png

———–
vim->email->wordpress

给apache添加一个动态模块

http://www.phpchina.com/manual/apache/programs/apxs.html

火星啊,可耻的重编流。。
/opt/apache/bin/apxs -c -i -a mod_proxy_connect.c

———–
post by gmail~

apache的REQUEST_FILENAME变量

老早之前就发现REQUEST_FILENAME不准的问题,当时对中文文档深信不疑。
中文文档

REQUEST_FILENAME
这是与请求相匹配的完整的本地文件系统的文件路径名。

英文文档

REQUEST_FILENAME
The full local filesystem path to the file or script matching the request, if this has already been determined by the server at the time REQUEST_FILENAME is referenced. Otherwise, such as when used in virtual host context, the same value as REQUEST_URI.

看完e文文档就明了了,原来REQUEST_FILENAME在虚拟主机配置上下文里是跟REQUEST_URI一样的。。