Reloading an Image

Discussion in 'PHP' started by swtectonics, Dec 1, 2007.

  1. #1
    I have images I regularly update on the same page via my PHP cms with the same filename. This causes a problem that the viewers that visit my page do not see the updated image unless they refresh their pages. How can I avoid this?
     
    swtectonics, Dec 1, 2007 IP
  2. Kwaku

    Kwaku Well-Known Member

    Messages:
    1,217
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    140
    #2
    add;

    <img src="image.jpg?<?=rand(1,1000)?>">

    If you want to do it right and have users use their client cache, you would do it like this;

    <img src="image.jpg?<?=$cur_image_refresh?>">

    where $cur_image_refresh only changes when the CMS changes the pic.
     
    Kwaku, Dec 1, 2007 IP
  3. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    instead of naming the file the same way it uploaded, give it a version number so that the filename is different.

    image_1.jpg

    As long as the user agents thinks it a different request itll refresh.

    Kwaku's way will also work just fine :)
     
    tonybogs, Dec 2, 2007 IP