kid_drew Posted April 13, 2007 Share Posted April 13, 2007 So for the project I'm working on, I have an image that gets converted from an eps file fairly regularly. When you go to the page that displays that image (the gif, not the eps) it isn't aware that the image file has been updated in the background and it always loads the cached file unless I push refresh/reload. Is there a way in PHP/Apache to get that file to always load from the server rather than from cache? Or maybe in Javascript? Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 13, 2007 Share Posted April 13, 2007 Take a look at the header page in the php manual, the below example is there header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past You would output these headers and have the php script then output the image and you would instead reference the script instead of the actual image. Quote Link to comment Share on other sites More sharing options...
taith Posted April 13, 2007 Share Posted April 13, 2007 if you put an ajax script, which loads the pic, that'd kill the cache, or... if you just tell the header() to not use cache... both work :-) header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); there dies any/all forms of cache out there :-) Quote Link to comment Share on other sites More sharing options...
kid_drew Posted April 13, 2007 Author Share Posted April 13, 2007 Headers don't seem to be doing the trick. I read somewhere that the header cache calls are simply "suggestions" and don't actually force anything. How ridiculous is it that this is so diffucult? I've even tried the trick of making the image call unique like this: <img src="foo.gif?<?php echo rand(1,3000)?>"> And that doesn't even work. How do I make php display the image? if you put an ajax script, which loads the pic, that'd kill the cache, or... if you just tell the header() to not use cache... both work :-) header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); there dies any/all forms of cache out there :-) Quote Link to comment Share on other sites More sharing options...
taith Posted April 13, 2007 Share Posted April 13, 2007 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); echo '<img src="img.jpg">'; that should disable any cache on the page, telling the browser to reload the img each opening... Quote Link to comment Share on other sites More sharing options...
kid_drew Posted April 13, 2007 Author Share Posted April 13, 2007 That's using html to display the image, and that isn't working. header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); echo '<img src="img.jpg">'; that should disable any cache on the page, telling the browser to reload the img each opening... Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 13, 2007 Share Posted April 13, 2007 kid_drew, you would output the content-type for the image then readfile would do the trick header("Content-Type: image/gif"); readfile('myimage.gif'); Quote Link to comment Share on other sites More sharing options...
kid_drew Posted April 21, 2007 Author Share Posted April 21, 2007 Give me an example of an ajax script that would do this. Note that this image is not the only thing I'm displaying on the page and it will have to be embedded in html. Is that possible? if you put an ajax script, which loads the pic, that'd kill the cache, or... if you just tell the header() to not use cache... both work :-) header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); there dies any/all forms of cache out there :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.