Dyanmic Images Reload

S

STEPHEN GOODE

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
preference).

Rex
 
S

Steve

STEPHEN said:
3. Some really great way someone here is going to describe to me (my
preference).

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:

<?php
// 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...

?>
 
T

Tim Williams

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

Maybe just use js to reload only the image.

document.images["imgName"].src="getImage.php?blah="+escape(new
Date());

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.

Tim.
 
S

STEPHEN GOODE

Steve,

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.

Rex
 
S

STEPHEN GOODE

Tim,

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

Rex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top