If you are using code to update images, such as image magick or magickwand for PHP, your altered images may not be displaying when the page reloads, especially if the image saved to itself with the same name… Thus I have experienced this problem and am posting a solution. (continued after the jump)
What you need to do is add an extension to the images address. For this we will use the php function time().
1.) First we will generate a variable which holds the current time.
- $time = time();
2.) Next we need to add the time variable to our image’s source. Here are a few examples of how this can be used:
- img src=”logo.jpg?$time”
- img src=”$imgsrc?$time”
Obviously with those enclosed in < > tags
Your image tag will now be unique for every page reload and no longer will the image be reloaded from the cache.
If you copy your image address after it loads you will see the full effect, here is an example of what the address will look like:
- http://localhost/albums/images/image001.jpg?1247590307
As you can see image001.jpg is the image’s name and the time code is added after the “?“. The addition of the ? and time value will not alter the way the image appears.
Recent Comments