MinusMyThoughts Posted November 5, 2006 Share Posted November 5, 2006 I'm running into an issue with my image replacement feature. I can successfully upload, rename, and save an image to replace the old image, but when i view the updated page, i still see the cached image until i reload. i looked for cache clearing scripts through this forum, but the one i found didn't seem to work in IE or Firefox......is it possible to force a browser to reload? or should i try a different approach and rename my new images to something different and use a database to store the new image name?...obviously, my life will be easier if i can just force a reload. any ideas?love,jason Link to comment Share on other sites More sharing options...
skym Posted November 5, 2006 Share Posted November 5, 2006 Try this:<img src="image.jpg?anything=<?php echo rand(1,1000); ?>"> Link to comment Share on other sites More sharing options...
MinusMyThoughts Posted November 5, 2006 Author Share Posted November 5, 2006 how does that work? i figure if i understand the command, i won't need to ask again......also, i'm generating my img tag with php, so can i get the same effect using this? $pic1 = '<img src="images/userPics/pic1.gif?anything=' . rand(1,1000) . '" align="left">'; love,jason Link to comment Share on other sites More sharing options...
skym Posted November 5, 2006 Share Posted November 5, 2006 Yes, it's the same thing. The browser will always look again for the image file, just like it would have another filename. Link to comment Share on other sites More sharing options...
shiftJIS Posted November 5, 2006 Share Posted November 5, 2006 That method works because everytime the image is displayed, it shows up as having a different uri. Thus, when you load the page once, it might be pic1.gif?anything=42, and when you reload it'll be pic1.gif?anything=981. Because these uri are different, the browser caches them as different images, forcing a reload everytime (unless theres the odd chance that you get the same number again). Link to comment Share on other sites More sharing options...
jlhaslip Posted November 6, 2006 Share Posted November 6, 2006 Caching can also be avoided during a Development stage by using a Meta-tag with an already passed date. Google on "meta expires= tag" for more info, but here are two sample meta-tags which work: <meta http-equiv="expires" content="0"> <meta http-equiv="expires" content="Tue Dec 31 23:59:59 GMT 2002"> Only one would be required. Link to comment Share on other sites More sharing options...
Lulzim Posted November 6, 2006 Share Posted November 6, 2006 you can also use these meta tags: <meta http-equiv="cache-control" content="no-cache"><meta http-equiv="pragma" content="no-cache"> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2006 Share Posted November 6, 2006 You can also send HTTP headers instead of using meta tags, which only work for HTML pages. If you create a script to display the image yourself, you can send headers to indicate that it should not be cached. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now