2016-08-13 138 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>