根据文件是否写入文件系统动态提供文件服务
标题很糟糕,但不知道如何很好地描述情况。 我想动态调整/裁剪图像。我希望将我的 apache 配置为执行以下操作:
- 收到 /img/profile.jpg?crop&p=50 的请求
- Apache 检查文件 /img/profile.c.50.jpg 是否存在
- 如果它确实存在,它静态地提供该服务,而无需访问我的 php 服务器
- 如果它不存在,它会访问 /cropper.php?path=/img/profile.jpg&p=50
- 然后该文件将图像写入文件,并提供服务它
- 请求再次出现(参见步骤 1)
我觉得我们可以使用 .htaccess 文件中的 FilesMatch 指令,但我真的不知道从哪里开始。任何链接或任何想法将不胜感激。
谢谢大家。
Terrible title, but don't really know how to describe the situation too well.
I would like to dynamically resize/crop images. I'm hoping to config my apache to do the following:
- A request for /img/profile.jpg?crop&p=50 is received
- Apache checks if the file /img/profile.c.50.jpg exists
- If it does exist, it serves that up statically without having to hit my php server
- If it doesn't exist, it hits /cropper.php?path=/img/profile.jpg&p=50
- This file then writes the image to file, and serves it
- Request comes in again (see step 1)
I feel like making use of the FilesMatch directive in the .htaccess file could be of us but I really don't know where to start. Any links would be appreciated, or any ideas.
Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
\就我个人而言,我会将这个任务委托给脚本(可能使用 X-Sendfile),而不是重写混乱。
在这里,您可能需要调整您的文档根目录并使您的“配置文件”部分更加通用:
始终涉及脚本的解决方案:
(为了清楚起见,通过 /img/profiles/... 访问)
这确实简化了重写:
该脚本将检查是否文件存在,然后先交付它或生成它
从请求的 URL 获取图像名称的解决方案:
(正如您在评论中提到的)
如果存储了图像,则可以将其重写为以下内容。直接在文档根目录中:
\Personally, I'd delegate this task to a script (maybe using X-Sendfile), rather than a rewrite mess.
Here you go, you may have to tweak your document root and make your "profile" part more general:
Solution always involving a script:
(accessed through /img/profiles/... for clarity)
Which really simplifies the rewrite:
The script would check whether the file exists and either deliver it or generate it first.
Solution taking the image name from the requested URL:
(As you mentionned in your comment)
which may be rewritten to the following, if the images are stored directly within your document root: