Forcing browser to download new copy of image

Discussion in 'PHP' started by stephan2307, Feb 26, 2010.

  1. #1
    Hi,

    I am having a website where depending on the the action of the user the images changes on the page load.

    Now the image url stays the same as I use php to manipulate the image. Because the image is already cached the browser does not download it again.

    How can I tell the browser to download the image again?

    Thanks
     
    stephan2307, Feb 26, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    never mind. sorted it

    This is the trick

    
    <a href="image.png?<? echo time(); ?>" />
    
    Code (markup):
     
    stephan2307, Feb 26, 2010 IP
  3. myveed

    myveed Peon

    Messages:
    82
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Stephan,

    You can try to make the url dynamic attaching query string something like..
    img src=xxx.php?t=".time()

    or send headers to ask the browser not to cache..

    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("cache-Control: no-store, no-cache, must-revalidate");
    header("cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
     
    myveed, Feb 26, 2010 IP
  4. HostingProvider

    HostingProvider Active Member

    Messages:
    1,480
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    95
    #4
    I'd personally use the headers myveed posted above to achieve that. You can also do that using .htaccess.
     
    HostingProvider, Feb 26, 2010 IP