By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,142 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,142 IT Pros & Developers. It's quick & easy.

Cache issue when updating image file

P: n/a
I am building a CMS and as part of it a user can upload an image.

Once uploaded I am displaying the image.

If the user then decides they want to replace the image with another I
get a caching issue in the browser as the image has the same name.

Without having to use unique file names each time the user replaces an
image, how can I force the browser to check for the file properly?

Thanks in advance,

Rick

Apr 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

thehuby wrote:
I am building a CMS and as part of it a user can upload an image.

Once uploaded I am displaying the image.

If the user then decides they want to replace the image with another I
get a caching issue in the browser as the image has the same name.

Without having to use unique file names each time the user replaces an
image, how can I force the browser to check for the file properly?

Thanks in advance,

Rick


Hey there

Setting http headers for the images will do, like,

Cache-Control: no-cache
Pragma: no-cache
Expires:0

You can use the header() function if the images are sent though php

If the images are stored in a directory and delivered by apache then
add these to the .htaccess file in the images directory

Header set Cache-Control "no cache"
Header set expires "0"
Header set pragma "no cache"

If your images are sharing a directory with html and other files (that
you may want cached) then read
http://www.linuxdevcenter.com/pub/a/...ly.html?page=2
for a flexible solution.

http://www.netapp.com/solutions/cache_basics.html was helpful too,
apparently the pragma header is often ignored but the other two headers
are reliable

No, thank you
Tim

Apr 25 '06 #2

P: n/a
thehuby wrote:
I am building a CMS and as part of it a user can upload an image.

Once uploaded I am displaying the image.

If the user then decides they want to replace the image with another I
get a caching issue in the browser as the image has the same name.

Without having to use unique file names each time the user replaces an
image, how can I force the browser to check for the file properly?


Quick dirty hack is to append a random number to the image like
<img src="foo.jpg?999" />-- so that the browser will think it always
getting different image.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

May 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.