2016-08-13 253 views
3

因此,我創建了一個php文件管理器,它將在表中列出服務器上目錄中的所有可用文件,併爲我提供下載或刪除選項。PHP下載,使用按鈕刪除和重命名文件

這是我的代碼:

<html> 
<head> 
    <title>My first PHP Page</title> 
</head> 

<body> 
    <iframe id="my_iframe" style="display:none;"></iframe> 
    <table border="1"> 
    <?php 
     $dir = 'uploads'; 
     $files = scandir($dir); 
     sort($files); 
     $count = -1 ; 
     foreach ($files as $file) { 
      if ($file != '.' && $file != '..') { 
       $str_URL = "uploads".$file; 
       echo "<tr>"; 
       echo "<td>"; 
       echo $count; 
       echo "</td>"; 
       echo "<td>"; 
       echo $file; 
       echo "</td>"; 
       echo "<td>"; 
       echo "<input type='submit' value='Download'/>"; 
       echo "</td>"; 
       echo "<td>"; 
       echo "<input type='submit' value='Delete'/>"; 
       echo "</td>"; 
       echo "<td>"; 
       echo "<input type='submit' value='Rename'/>"; 
       echo "</td>"; 
       echo "</tr>"; 
      } 
      $count++; 
     } 
    ?> 
</table> 
</body> 
</html> 

enter image description here

我能列出文件,但我不能得到的「下載」和「刪除」按鈕才能正常工作。

任何幫助非常感謝,非常感謝你提前。

+0

Y的ú使用提交?你的表格在哪裏? – coder

回答

-1

看我的代碼

<html> 
<head> 
    <title>My first PHP Page</title> 
</head> 

<body> 
    <iframe id="my_iframe" style="display:none;"></iframe> 
    <table border="1"> 
    <?php 
     $dir = 'uploads'; 
     $files = scandir($dir); 
     sort($files); 
     $count = -1 ; 
     foreach ($files as $file) { 
     $v_download = "download_".$count; 
     $v_delete = "delete_".$count; 
     $v_rename = "rename_".$count; 
      if ($file != '.' && $file != '..') { 
       $str_URL = "uploads".$file; 
       echo "<tr>"; 
       echo "<td>"; 
       echo $count; 
       echo "</td>"; 
       echo "<td>"; 
       echo $file; 
       echo "</td>"; 
       echo "<td>"; 
       echo "<form action='' method='post'><input type='submit' value='Download' name='".$v_download."'/></form>"; 
       if(isset($_POST[$v_download])) { 
       // Your php download code here 
       echo "download file : ".$file; 
       } 
       echo "</td>"; 
       echo "<td>"; 
       echo "<form action='' method='post'><input type='submit' value='Delete' name='".$v_delete."'/></form>"; 
       if(isset($_POST[$v_delete])) { 
       // Your php delete code here 
       echo "delete file : ".$file; 
       } 
       echo "</td>"; 
       echo "<td>"; 
       echo "<form action='' method='post'><input type='submit' value='Rename' name='".$v_rename."'/></form>"; 
       if(isset($_POST[$v_rename])) { 
       // Your php rename code here 
       echo "rename file : ".$file; 
       } 
       echo "</td>"; 
       echo "</tr>"; 
      } 
      $count++; 
     } 
    ?> 
</table> 
</body> 
</html>