无法从目录中删除图像

时间:2013-06-18 06:49:50

标签: php

我已经编写了这些脚本来删除目录中的文件(实际上是图像),但可以选择决定删除哪个文件并事先查看。 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');
?>

1 个答案:

答案 0 :(得分:1)

这是因为您没有删除delete.php中的图像

在路径文件上使用unlink

相关问题