Sam*_*min 0 php apache .htaccess
我的网络应用程序中有一个目录,我想保留所有用户个人资料图片.用户可以上传所有类型的图像(png,jpg,gif).但是,我希望图像URL友好,例如.http://example.com/static/picture/300-username,文件为300用户名,但没有扩展名.我想在用户上传时删除扩展名,并使用PHP控制器添加:
header('Content-Type: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png');
readfile('http://example.com/static/picture/300-username');
Run Code Online (Sandbox Code Playgroud)
这运作良好.我想知道,如果可以通过将.htaccess文件放在图片目录中,使用某种Header,无论在此目录中读取什么文件,都会显示为图片.这可能吗?
不要删除扩展名,只提供无扩展名的URI /static/picture/300-username.然后在.htaccess中添加一行:
Options +MultiViews
Run Code Online (Sandbox Code Playgroud)
Apache将为您设置正确的内容类型.请参阅内容协商的文档.