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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题