473,809 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2242

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?99 9" />-- 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
2602
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 date (not older than file) if not, modify filename and store in cache (keyed by filename + modification) return modified image
4
1711
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 most of the time images r same.. so i just need to store image in cache...but not data..becoz asp page reads all phone list information from database and displays all phones... so is it possible to store image in cache so it can be served quickly...
2
4091
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 change, this require to prevent this image from being cached, I have tried to play around with: Context.Response.AddHeader("Cache-Control", ... ) and with Context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache) BUT Still, the...
2
1003
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 the files inside a directory, stuff them into an array, then put that array into the ASP.NET data cache. I want the cache to expire and be repopulated when a file is added or removed from that image directory.
1
1428
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 change, this require to prevent this image from being cached, I have tried to play around with: Context.Response.AddHeader("Cache-Control", ... ) and with Context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache) BUT Still, the...
1
2517
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); imagejpeg($im2,"temp100.jpg",100); imagejpeg($im2,"temp75.jpg",75); imagejpeg($im2,"temp50.jpg",50); imagejpeg($im2,"temp25.jpg",25);
2
5334
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 uploaded is the png image. But the new images gets uploaded and also the old images is getting deleted I assume this is a caching issue. does anyone know of some code I can put into my PHP to clear the cache from certain pages???
3
4018
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, while width and height is user specific - meaning user can change this on demand. My question is, although this rendering images on the fly is cool, I would like to implement some sort of mechanism/logic that it wont keep rendering the thumbnail...
7
2025
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 immediately invalidated. e.g. Cache.Insert("myobj", data, new CacheDependency(filePath)); When I make a change to the file 'filePath' and call the object from the cache it is not null. I'm disposing of the FileStream object immediately
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.