PHP: Issue with deleting files from server?

S B

New member
I have a file called removepics.php which lists all the pictures a user has on my server and gives the options to delete any one (using a form and submit button which calls removepics2.php).

removepics2.php removes the file from the server successfully, and then redirects back to removepics.php so the user can remove another picture (it does this using a form and submit button again).

But when removepics.php is reloaded, the deleted picture is still there. I'm thinking it has something to do with cookies?

I want the deleted picture to not be there. Any help would be greatly appreciated.

Here is my code for removepics2.php:
-------------------------------------------------
<?php
$PicNum = $_POST['picnum'];
$HouseNum = $_POST['housenum'];
$EmailAddress = $_POST['emailaddress'];

unlink('../forms/uploaded_files/'.
$HouseNum.'-'.$PicNum.'.jpg');

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"';
echo '"http://www.w3.org/
TR/html4/strict.dtd">';

echo '<html lang="en">';
echo '<form method="post" name="myform" action="removepics.php">';
echo '<input type="hidden" name="emailaddress" value="'.$EmailAddress.'" >';
echo '<input type="hidden" name="housenum" value="'.$HouseNum.'" >';
echo '<input type="submit">';
echo '</form>';

echo '<script>';
echo 'document.myform.submit();';
echo '</script>';

?>
---------------------------------------------------
 
You are thinking along the right lines.. but its not cookies causing the problem. The problem is with the users browser cache displaying a saved version of the image. I also had this problem and found this solution.

What you do is wherever the image is displayed it has a query string attached to it that is a random value. What this does is to force the image to be reloaded from the server - and not from the cached version on the users computer. Like this:

$randVal = rand();
echo "<img src='image.jpg?randVal=$randVal'>";
 
Back
Top