doujian7132 2011-08-25 16:45
浏览 34
已采纳

使用php调整大小和缓存图像,并使用mod_rewrite访问缓存的图像

I want to resize images with the size in the url like this: http://www.domain.nl/images/chached/200x200/name.jpg If the image doesn't exist I want to generate and cache it.

How do I after that check if the file exists, with out having to generate the folder '200x200' in the /images/chached/ directory and without the use of PHP(slower).

Is there a way to do this with mod_rewrite(faster)? Or is this just not possible?

I'm using Kohana 3 witch uses this mod_rewite code:

# Turn on URL rewriting
RewriteEngine On
# Installation directory
# RewriteBase /kohana/
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
  • 写回答

1条回答 默认 最新

  • duanlu9970 2011-08-25 17:54
    关注

    Use Kohana's routing to set up a new route /images/cached/<size>/<name> (or similar) and let it be handled by an action of your choice. Then, in the code for that action, generate the image from those parameters, save the result under that path, AND serve the image to the client.

    So the first request (file doesn't exist) goes straight to index.php (because RewriteRule .* index.php/$0 [PT]), the second and every following request will be served by Apache directly (because now RewriteCond %{REQUEST_FILENAME} !-f doesn't match anymore).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义