我已经编写了这些脚本来删除目录中的文件(实际上是图像),但可以选择决定删除哪个文件并事先查看。 view.php
脚本似乎工作正常,但delete.php
似乎无法正常运行,因为图片没有移除。
这是脚本:
view.php
<?php
$path = '../product-uploads/gloves/'; // path for each page
$files = glob("{$path}*.*"); // Get the files
$files = array_filter($files, 'is_file'); // Get rid of directories
$dates = array_map('filectime', $files); // Get the creation times.
$md5s = array();
array_multisort($dates, $files, SORT_NUMERIC); // in order of creation
foreach ($files AS $file)
{
$hash = md5_file($file);
if (!in_array($hash, $md5s))
{
$md5s[] = $hash;
echo "<img src=\"$file\" /> <br />
<form action=\"delete.php\" method=\"post\">
<input type=\"hidden\" name=\"Name\" value=\"$file\">
<input type=\"submit\" value=\"Delete\">
</form>";
}
}
?>
delete.php
<?php
$path = '../product-uploads/gloves/';// images are here
$Name = $_POST['Name'];
$PathFile = $path.$Name;
$PathFile = basename($PathFile);
header('Location: view.php');
?>