PHP 使用按钮下载、删除和重命名文件
Posted
技术标签:
【中文标题】PHP 使用按钮下载、删除和重命名文件【英文标题】:PHP download, delete and rename files with buttons 【发布时间】:2016-12-20 07:42:40 【问题描述】:所以我正在使用 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>
我可以列出文件,但无法让“下载”和“删除”按钮正常工作。
非常感谢任何帮助,并在此先感谢您。
【问题讨论】:
你在使用提交吗?你的表格在哪里 【参考方案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>
【讨论】:
以上是关于PHP 使用按钮下载、删除和重命名文件的主要内容,如果未能解决你的问题,请参考以下文章
Java API在HDFS上实现文件的上传下载到本地创建文件夹删除文件和重命名文件