How to force browser to reload image from server?

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

    How to force browser to reload image from server?

    This is probably more of an HTML question than PHP. Perhaps someone
    here can answer or point me to a proper newsgroup.

    How can I force the browser to reload an image from the server?

    I have a page where the user can set some parameters and click a
    <submit> button. A PHP script then generates a .png graphic and saves
    it to disc. An html statement (<p><img src="gMyGraphic .png"></p>) then
    sends the graphic out to the browser.

    This works as expected - the first time. But when the user modifies a
    parameter and re-submits the page, the modified graphic does not get
    sent to the browser. I know the graphic is being updated - I can look
    at it on the server's hard drive (and I'm displaying some other
    information on the page that indicates it's been updated).

    If I "refresh" the page in the browser, then the modified graphic IS
    displayed.

    It appears that the browser is using a cached copy of the graphic -
    even though I've told it not to cache anything. The page includes the
    following statements:

    <META HTTP-EQUIV="expires" CONTENT="Wed, 09 Aug 2000 08:21:57 GMT">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">


  • Daniel Tryba

    #2
    Re: How to force browser to reload image from server?

    Martin <martinvalley@c omcast.net> wrote:[color=blue]
    > How can I force the browser to reload an image from the server?[/color]

    See the thread 'Image not refreshing' started on the 16th bij Ken.
    (http://groups.google.com/groups?selm....rdc-kc.rr.com)

    Quick fix messageid: <1n2f93lvdreny$ .yqiy0gnsfyfx.d lg@40tude.net>

    --

    Daniel Tryba

    Comment

    • Chung Leong

      #3
      Re: How to force browser to reload image from server?

      "Martin" <martinvalley@c omcast.net> wrote in message
      news:2f83l0hvjg qhr0a645400cdg6 oi2u6k5ai@4ax.c om...[color=blue]
      > This is probably more of an HTML question than PHP. Perhaps someone
      > here can answer or point me to a proper newsgroup.
      >
      > How can I force the browser to reload an image from the server?
      >
      > I have a page where the user can set some parameters and click a
      > <submit> button. A PHP script then generates a .png graphic and saves
      > it to disc. An html statement (<p><img src="gMyGraphic .png"></p>) then
      > sends the graphic out to the browser.[/color]

      The easiest way is to stick a random number into the URL:

      <img src="gMyGraphic .png?<? echo rand(1,3000); ?>">

      Consider outputting the image data directly from the PHP script to the
      browser.


      Comment

      • Simon Stienen

        #4
        Re: How to force browser to reload image from server?

        Chung Leong <chernyshevsky@ hotmail.com> wrote:[color=blue]
        > "Martin" <martinvalley@c omcast.net> wrote in message
        > news:2f83l0hvjg qhr0a645400cdg6 oi2u6k5ai@4ax.c om...[color=green]
        >> This is probably more of an HTML question than PHP. Perhaps someone
        >> here can answer or point me to a proper newsgroup.
        >>
        >> How can I force the browser to reload an image from the server?
        >>
        >> I have a page where the user can set some parameters and click a
        >> <submit> button. A PHP script then generates a .png graphic and saves
        >> it to disc. An html statement (<p><img src="gMyGraphic .png"></p>) then
        >> sends the graphic out to the browser.[/color]
        >
        > The easiest way is to stick a random number into the URL:
        >
        > <img src="gMyGraphic .png?<? echo rand(1,3000); ?>">
        >
        > Consider outputting the image data directly from the PHP script to the
        > browser.[/color]

        time() instead of rand() should suffice and is even more easier... and you
        won't get the old image by random... (you have a 1 in 3000 chance to see
        the old image again...)

        Maybe a bit more complex, but even better than rand() or time() would be
        <img src="myimage.pn g?<?php echo filemtime('myim age.png') ?>">
        since it doesn't *completely* turn off caching.

        --
        Simon Stienen <http://dangerouscat.ne t> <http://slashlife.de>
        »What you do in this world is a matter of no consequence,
        The question is, what can you make people believe that you have done.«
        -- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle

        Comment

        • Martin

          #5
          Re: How to force browser to reload image from server?

          On Thu, 23 Sep 2004 09:05:34 +0200, Simon Stienen
          <simon.stienen@ news.slashlife. de> wrote:
          [color=blue]
          >Chung Leong <chernyshevsky@ hotmail.com> wrote:[color=green]
          >> "Martin" <martinvalley@c omcast.net> wrote in message
          >> news:2f83l0hvjg qhr0a645400cdg6 oi2u6k5ai@4ax.c om...[color=darkred]
          >>> This is probably more of an HTML question than PHP. Perhaps someone
          >>> here can answer or point me to a proper newsgroup.
          >>>
          >>> How can I force the browser to reload an image from the server?
          >>>
          >>> I have a page where the user can set some parameters and click a
          >>> <submit> button. A PHP script then generates a .png graphic and saves
          >>> it to disc. An html statement (<p><img src="gMyGraphic .png"></p>) then
          >>> sends the graphic out to the browser.[/color]
          >>
          >> The easiest way is to stick a random number into the URL:
          >>
          >> <img src="gMyGraphic .png?<? echo rand(1,3000); ?>">
          >>
          >> Consider outputting the image data directly from the PHP script to the
          >> browser.[/color]
          >
          >time() instead of rand() should suffice and is even more easier... and you
          >won't get the old image by random... (you have a 1 in 3000 chance to see
          >the old image again...)[/color]

          Good suggestion - thanks.

          I added the rand(1,100) and it worked but, like you say, I was getting
          an old image every once in a while. I changed it to rand() which
          eliminated that but the potential is still there. With time(), it's
          guaranteed to always be a different number.

          [color=blue]
          >
          >Maybe a bit more complex, but even better than rand() or time() would be
          ><img src="myimage.pn g?<?php echo filemtime('myim age.png') ?>">
          >since it doesn't *completely* turn off caching.[/color]

          Comment

          Working...