【发布时间】:2012-04-05 09:53:11
【问题描述】:
我正在尝试创建一个 php 文件,该文件将扫描一个目录,制作一个动态单选按钮列表,让用户选择一个并提交它,它会将其传递到另一个 php 文件中,然后将其发送出去,但我提交按钮有问题。想知道我是否能得到一些答案,在网上四处寻找,却找不到任何东西。 这是我的代码:
<?php
ini_set('display_errors',true);
//Scan directory (ripped from another site)
$directory = opendir("download");
while($entry = readdir($directory)) {
$dirArray[] = $entry;
}
closedir($directory);
$indexCount = count($dirArray);
sort($dirArray);
//Make the Radio Button list
$RList = "";
for($i=2; $i<count($dirArray); $i++) {
$value = $dirArray[$i];
$RList .= "<input type=\"radio\" name=\"Files\" value=".$value." />".$value."<br />";
}
//Submit button
$RButton = '<input type="button" value="Submit"
onclick="location.href=\'http://localhost/appClient/load.php?file='.$value.'\'">';
echo $RList.$RButton;
#echo $_POST["Files"];
?>
谢谢
【问题讨论】:
-
你遇到了什么麻烦?什么不适用于您当前的代码?请更具体。
-
你的单选按钮和提交按钮太多了!
-
@JamWaffles 当我单击提交时没有获取正确的文件,因此 $value 存在问题,没有传递正确的数据。那么,您将如何在提交点击时将用户选择的文件名传递给 load.php?
标签: php dynamic radio-button