How to clear browser cache when re-uploading image with same filename, in php?

后端 未结 8 1523
灰色年华
灰色年华 2021-02-18 19:05

I have a listing of items, that also contains an image thumbnail. Sometimes I need to change the thumbnail image, but keep the filename the same. Is there a way to force the bro

相关标签:
8条回答
  • 2021-02-18 19:45

    You can add last modified date to you image or simply add date and time at the end of you image URL

    for Example

    $today=date('Y-m-d H:i');
    
    <img class="img-circle pro_pic" src="https://govcard.net/yourimage.jpg?lm=<?php echo $today?>" alt=""> 
    

    after .jpg add date and time like this. hope this will help you.

    0 讨论(0)
  • 2021-02-18 19:48

    Cached images are also invalidated on manual page refresh (pressing F5 in browser). This can be simulated with Javascript method location.reload() being fired on body load. To avoid perpetual reloading, this may take place only once. When the user uploads a new avatar, the ReloadPending request is set persistently in his/her session and it is reset when it's been answered.

    <?php
    if ($session['ReloadPending']) 
    {   $session['ReloadPending']=false; 
           echo "<body onload='location.reload(true);'>"; 
    } else echo "<body>";
    ?>
    

    Reloading the whole page after avatar upload will cause the page flicker but this happens only once, which, I believe, is acceptable.

    0 讨论(0)
提交回复
热议问题