Dyanmic Images Reload

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • STEPHEN GOODE

    Dyanmic Images Reload

    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


  • Steve

    #2
    Re: Dyanmic Images Reload


    STEPHEN GOODE wrote:[color=blue]
    > 3. Some really great way someone here is going to describe to me (my
    > preference).[/color]

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

    ?>

    ---
    Steve

    Comment

    • Tim Williams

      #3
      Re: Dyanmic Images Reload

      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="+esca pe(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.


      "STEPHEN GOODE" <rexgoode@veriz on.net> wrote in message
      news:oXYxd.3602 $hc7.1541@trndd c06...[color=blue]
      >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
      >
      >[/color]


      Comment

      • STEPHEN GOODE

        #4
        Re: Dyanmic Images Reload

        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


        Comment

        • STEPHEN GOODE

          #5
          Re: Dyanmic Images Reload

          Tim,

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

          Rex


          Comment

          Working...