0

I have website where every user have a cover image in profile page and it's name constant every time main_cover.jpg, my problem that every time user upload image the image not show because old image cached in browser and i must do ctrl+f5 to recache the page to show the new image , so i want browser to cache image every time but show new image when upload and i don't want to use datatabase to save new image name i want to use just this name main_cover.jpg.

<?php
echo '<img src="main_cover.jpg" alt="'.$username.'" >';
?>
tobili
  • 41
  • 4

1 Answers1

1

the easiest and the simplest way to do this by get file modified time and but it after image url so every time user upload new image the browser recache the image .

<?php
$lm=filemtime('main_cover.jpg');
echo '<img src="main_cover.jpg?'.$lm.'" alt="'.$username.'" >';
?>
Mo Shal
  • 1,587
  • 18
  • 25