2013-06-18 108 views
-1

我已經編寫了這些腳本來刪除目錄中的文件(圖像,實際上),但可以選擇決定先刪除和查看哪一個文件。 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'); 
?> 
+2

準確地在哪一行刪除文件? – Carsten

+0

我看不到任何腳本中實際嘗試刪除的任何內容...... – John3136

+0

您沒有做任何刪除操作。嘗試unlink(),刪除一個文件。 –

回答

1

這是因爲你沒有在你的delete.php刪除圖像

在pathfile上使用unlink