php和htaccess,如何仅在一个目录中禁用图像缓存

我的根目录中有一个htaccess文件,其中包含以下缓存说明:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>

现在我刚刚注意到,当我使用php / ajax上传图像时,在图像预览中首次显示了正确的图像,但是,如果我重新上传/覆盖图像,则预览不会更改,可能是因为htaccess缓存指令.

是否可以仅在目录/ upload /中删除chache,或者更好地,仅在总是正确显示预览的方式中仅在upload / preview php脚本中禁用chche?

解决方法:

使用以下命令将另一个.htaccess文件添加到上传文件夹中

ExpiresActive Off

或ExpiresByType用于0秒的图像

或者,在预览脚本中将缓存破坏者添加到图像标签中:

src="/uploads/image.jpg?<?php print time(); ?>"
上一篇:PHP将URL传递给index.php


下一篇:htaccess重定向到另一个目录