从文件夹中删除上传的图片


Delete uploaded picture from a folder

您好,我得到了这个php代码,它将图像保存到名为"upload"的文件夹中,并将图片保存为会话。但是在图片另存为会话后,我想从文件夹中删除它......我不知道怎么做。请帮忙:)

  //something.php
 <?php 
  session start();
 $filename    = $_FILES["picture"]["tmp_name"];
$destination = "upload/" . $_FILES["picture"]["name"]; 
move_uploaded_file($filename, $destination);
$_SESSION['picture'] = $destination;
  ?>

这是我的 html 表单:

<form action="something.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="picture" id="picture">
    <input type="submit" value="Upload Image" name="submit">
</form>

您不会将图像数据保存到会话,而只会将文件的路径保存。因此,删除"文件"将从服务器中删除数据,我认为您不想这样做。但如果你这样做了,你会这样做:

unlink($destination)

unlink($_SESSION['picture'])

将图像数据存储在 $_SESSION 变量中不是一个好主意,您应该将其保存到可以保存它的服务器中。