I have a piece of code to upload a picture and save it in a folder and the path in a databaseand show it on the webpage. Funny enough, upon uploading the picture for the first time, the image will show on the webpage and with change when I upload a new picture. But when I close the page, reopen it another day and decide to change the picture, the one of the webpage won’t change even if i refresh the page but the one in the folder will change.
Here’s my code
<?php $sql2 = "SELECT Picture_HD FROM detailss WHERE Idn_nom = '$Indnum'"; require('connect.php'); $addr = ""; $addr = mysqli_query($conn, $sql2); if ($addr) { $locat = $addr->fetch_row(); $locat = (string)$locat[0]; } else { $locat = "Pictures/default1.png"; } mysqli_close($conn); echo "<div id = 'Img'>"; echo "<img src = '" . $locat . "' alt = 'Passport picture/Headshot' style = 'width:80px; height:80px;'/>"; echo "</div>"; ?>
Advertisement
Answer
Your browser is caching the image. If you want to prevent the browser to cache the image just add a random parameter at the end of the url.
echo "<img src = '" . $locat . "?t=" . time() . "' alt = 'Passport picture/Headshot' style = 'width:80px; height:80px;'/>";