Dyanmic Images Reload

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a php script that dynamically creates images, reusing image files on
the server to save space and clutter.

The problem is described in the steps below:

1. User clicks on a button.
2. Same page loads, but the php script creates a new image in an old file.
3. It displays the image file, but the old image shows, even though the file
contains the new image.

My options are:

1. Use javascript to force a reload when the user clicks the button (not
desirable, because the user is forced to confirm the reload by the browser).
2. Put a cheesy blurb on the page telling the user to reload or refresh
(along with ideotic explanations of how to do it).
3. Some really great way someone here is going to describe to me (my


Re: Dyanmic Images Reload

Quoted text here. Click to load it

Add a 'please don't cache me' header to the script creating the image
files. See http://www.php.net/manual/en/function.header.php

NB header() lines must all be issued before any other output is sent to
the browser (but you knew that already). Something along the lines of:

// a date in the past...
header( "Expires: Sat, 18 Mar 2000 00:00:01 GMT" );
// hint...
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
// don't cache me...
header( "Cache-Control: no-cache, must-revalidate" );
// no, really...
header( "Pragma: no-cache" );
// it's a piccy...
header( "Content-type: image/jpeg" );
// rest of image code...



Re: Dyanmic Images Reload


Thanks. I couldn't get it to work. It all seemed to be working. I mean, the
header calls were all done right and before any other output, but it still
cached those images.

What worked was what Tim suggested in another reply. I'm still hoping to
figure out why the headers didn't work.

Thanks again.


Re: Dyanmic Images Reload

Do you need to reload the whole page, or will refreshing the image be

Maybe just use js to reload only the image.


or something like that.  Adding a fake querystring to your image src
will persuade the browser to refetch the image instead of using the
cached version.  You might also experiment with adding "no-cache"
headers to your image when you serve it up.


Quoted text here. Click to load it

Re: Dyanmic Images Reload


Thanks. That worked. Don't know why the no-cache stuff didn't work, but I
plan to figure it out.


Site Timeline