TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   No cache display of image? (http://www.talkphp.com/general/3075-no-cache-display-image.html)

delayedinsanity 07-06-2008 03:03 AM

No cache display of image?
 
Is there a way I can use PHP to force an image to display?

I don't want to set no-cache headers via my .htaccess as I have it doing exactly the opposite for the rest of the site images (far-future expires), and I don't want the script to rely on any outside caching/no-caching directives.

Right now I display a users avatar with a simple little function that just determines if one exists for them then creates the HTML img element for it and echo's that back to the browser. This works fine for the most part except that when a new avatar is uploaded, the page that loads displays the old image until you refresh the browser, and I want it to display immediately.
-m

Kalle 07-06-2008 05:07 AM

You can try send some HTTP headers on the page that the image shows on or if the image is outputted though php you can put these headers in that file before sending it to the browser:

PHP Code:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

cheers

delayedinsanity 07-06-2008 06:25 AM

I thought of that, but I was trying to avoid having an additional script to display the avatars (http://localhost/images.php?myimage kinda deal) that it didn't cross my mind just to put them directly into the headers of the page that displayed the avatar.

Thanks you.
-m


All times are GMT. The time now is 06:19 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0