473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cache issue when updating image file

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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Дамјан Георгиевски | last post by:
I'm looking for a way to cache some modified images as files (in a python program ofcourse). The scenario would look like this: getmodifiedimage(filename): is it in cache? is the cache up to...
4
by: dave | last post by:
hi I'm building a page that displays all phone in phoneview.asp...however from admin section we can add new phone image tht stores path in database. I wanna use cache object in phoneview.asp..becoz...
2
by: Nadav | last post by:
Hi, I am new to WebControls, I have created a WebControl that is used to present an image, the image bing presented is created on runtime, each client side button click causes the image to...
2
by: Jason Dean | last post by:
Hello, Can anybody tell me if it's possible to create a dependency on the contents of a directory? For example, I've just built and ASP.NET image rotator that uses System.IO to loop through all...
1
by: Nadav | last post by:
Hi, I am new to WebControls, I have created a WebControl that is used to present an image, the image bing presented is created on runtime, each client side button click causes the image to...
1
by: Jaak | last post by:
I have a problem with cached images... The script first creates some pictures out of avariable source (every time the script runs the pics are different): $im = imagecreatefromjpeg($file);...
2
by: raji20 | last post by:
I'm frequently updating images on my site when the users clicks on the submit button, and some users have reported they are seeing old images where new ones should be... The image that is getting...
3
by: wardemon | last post by:
Hi All, I have a aspx page named: ImageProcess.aspx that creates a thumbnail version of an image by passing the ImagePath, width, and height. The ImagePath is taken from a table from a database,...
7
by: Andrew Jocelyn | last post by:
Hi I'm running an ASP.NET web application under IIS. I'm inserting a cache object with a file based CacheDependency. I've noticed that when the file changes the Cache object is not always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.