查看浏览器图像无扩展名扩展名、图像、浏览器

2023-09-02 00:39:02 作者:呐喊,@の咆哮,@

我有一个目录在我的web应用程序,我想保留所有的用户个人资料图片。用户可以上传所有类型的图像(PNG,JPG,GIF等)。不过,我想图像URL是友好的,如。 http://example.com/static/picture/300-username ,文件为300名,但没有扩展名。我想删除的扩展,当用户上传,并与一个PHP控制器,添加一个:

I have a directory in my web app where I want to keep all the user profile pictures. Users can upload all types of images (png, jpg, gif). However, I want the image URL to be friendly, eg. http://example.com/static/picture/300-username, where the file is 300-username, but with no extension. I thought of removing the extension when the user uploads, and with a PHP controller, add a:

header('Content-Type: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png');
readfile('http://example.com/static/picture/300-username');

这一直运作良好。我在想,但是,如果这可以通过将一个.htaccess文件中的图片目录,具有某种头,即任何文件被读这个目录中完成,将显示为图片。这可能吗?

This has worked well. I was wondering however, if this can be done by placing an .htaccess file in the picture directory, with some sort of Header, that whatever file is read in this directory, will display as picture. Is this possible?

推荐答案

不要取出扩展,只是提供扩展名的URI像 /静态/图片/ 300用户名 。然后一行添加到您的.htaccess:

Don’t remove the extension, just offer extensionless URIs like /static/picture/300-username. Then add a line to your .htaccess:

Options +MultiViews

阿帕奇会为你正确的内容类型。请参阅内容协商的文档。