ipel
ipel

Reputation: 1348

php and htaccess, how to disable images cache in only one directory

I have a htaccess file in my root with this cache instructions:

<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>

now I have just noted that when I upload an image with php/ajax the first time in the image preview is shown the corret image, however if I reupload/overwrite the image the preview don't change, probably for the htaccess cache intructions.

is possibile to remove the chache only in the directory /upload/, or better, disable the chache only in the upload/preview php script in way the the preview is always shown correctly?

Upvotes: 3

Views: 2245

Answers (1)

JamesG
JamesG

Reputation: 1697

Add another .htaccess file into the upload folder with

ExpiresActive Off

Or ExpiresByType for images with 0 seconds

Alternatively add a cache breaker to your image tags in the preview script:

src="/uploads/image.jpg?<?php print time(); ?>"

Upvotes: 4

Related Questions