0

this is my code in image_display.php:

<?php
$conn=  mysqli_connect("localhost","root","","crud");
$query = mysqli_query($conn, "select * from upload");
while($data = mysqli_fetch_assoc($query)) {
  ?>
 <img src="http://localhost/server/file_upload/<?php echo $data['location'] ?>"
    height="200" width="200"/>
    <a href="delete.php?path=<?php echo $data['location'] ?>
    &id=<?php echo $data['id'] ?>">Delete</a>
<?php
}

?>

and in delete.php:

<?php
$path = $_GET['path'];
$id = $_GET['id'];
chown($path,777);
if(unlink($path)) {
    $conn=  mysqli_connect("localhost","root","","crud");
    $query = mysqli_query($conn, "delete from upload where id='$id'");
    header('location: show.php');
}

?>

it was working without any problem? suddenly shows me this warning and not deleted?

Warning: unlink(files/decoration.png ): Permission denied in C:\xampp\htdocs\server\file_upload\delete.php on line 5

how can I enter as an root or admin in windows?

Osama Mohammed
  • 2,433
  • 13
  • 29
  • 61
  • That might not be a problem at all. E.g. if the file is already deleted. Consider to make the operation idempotent (repeatable) and don't error if a file already has been deleted. Operations on the file-system are often prone to race-conditions as the file-system is shared across all processes on the system. This is also the reason why files must use a different name than the one suggested by any uploader (make the name unique for the overall application lifecycle). – hakre Nov 20 '22 at 15:14
  • the file doesn't deleted – Osama Mohammed Nov 20 '22 at 15:18
  • Then you have a permission issue deleting an actual file. Consult the documentation of your file-system what the requirements are that deletions can be done and compare with the concrete configuration you have at hand. – hakre Nov 20 '22 at 15:20
  • the problem is just before one hour it was working !!! – Osama Mohammed Nov 20 '22 at 15:26
  • Yes, this happens. There is a new situation the (unchanged) code path never needed to address. You have two options (basically): a) restore the last known good configuration b) analyse the configuration change and address it appropriately: either with a configuration or with a code change - depending on your preference. /edit: Regarding `how can I enter as an root or admin in windows?`: This information should be first of all available in the documentation of your operating system. Additionally Q&A may cover this, either on-site or in a different one on Stackexchange. – hakre Nov 20 '22 at 15:32

0 Answers0