gpt4 book ai didi

PHP 使用按钮下载、删除和重命名文件

转载 作者:太空宇宙 更新时间:2023-11-04 13:27:59 25 4
gpt4 key购买 nike

因此,我正在使用 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

我可以列出文件,但无法使“下载”和“删除”按钮正常工作。

非常感谢任何帮助,并提前致谢。

最佳答案

看我的代码

<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 使用按钮下载、删除和重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38932422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com