使用PHP和MySQL缓存已调整大小的图像的最佳方法 [英] Best way to cache resized images using PHP and MySQL

查看:103
本文介绍了使用PHP和MySQL缓存已调整大小的图像的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PHP处理图像缓存的最佳实践方法是什么。

What would be the best practice way to handle the caching of images using PHP.

文件名当前存储在MySQL数据库中,该数据库重命名为GUID on上传,以及原始文件名和alt标签。

The filename is currently stored in a MySQL database which is renamed to a GUID on upload, along with the original filename and alt tag.

当图像放入HTML页面时,使用诸如'/ images / get /之类的URL完成200x200 / {guid} .jpg,重写为php脚本。这允许我的设计者指定(​​粗略地 - 源图像可能更小)文件大小。

When the image is put into the HTML pages it is done so using a url such as '/images/get/200x200/{guid}.jpg which is rewritten to a php script. This allows my designers to specify (roughly - the source image maybe smaller) the file size.

php脚本然后创建一个大小的哈希值(url中为200x200)和GUID文件名,如果之前已生成文件(文件名为hash存在于TMP目录中)从应用程序TMP目录发送文件。如果散列文件名不存在,则创建它,写入磁盘并以相同方式提供,

The php script then creates a hash of the size (200x200 in the url) and the GUID filename and if the file has been generated before (file with the name of the hash exists in TMP directory) sends the file from the application TMP directory. If the hashed filename does not exist, then it is created, written to disk and served up in the same manner,

这是否有效? (它还支持对图像加水印,并且水印设置也存储在哈希中,但这超出了范围。)

Is this efficient as it could be? (It also supports watermarking the images and the watermarking settings are stored in the hash as well, but thats out of scope for this.)

推荐答案

Dan Udey的重写示例中有两个拼写错误(我无法评论),它应该是:

There is two typos in Dan Udey's rewrite example (and I can't comment on it), it should rather be :

RewriteCond %{REQUEST_URI} ^/images/cached/
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule (.*) /images/generate.php?$1 [L]

问候。

这篇关于使用PHP和MySQL缓存已调整大小的图像的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆