Force Image Refresh

I was having some caching problems with a project I was working on. The page gives the user the ability to upload images, and upon uploading, shows a thumbnail. This can be deleted form the page. The problem came when the user deleted the file, and then added another one. The filenames are generate din sequential order, so sometimes the deleted file had the same name as the new file. This causes the browser to show the image that's in the cache (the deleted one), instead of the new one. If you didn't understand that first paragraph, what I basically need to do is to reload an image in the page, without reloading the whole page. The solution, it seems, is quite simple. I'm using PHP to generate the pages, so I just did something like this: < img src="mypic.jpg?" /> In effect, this generates a random number at the end of each image to trick the browser into thinking it's a new image. I came to this solution after reading this thread about the same thing using javascript.

Leave a Comment

Your Comment