第一页,使用什么建议在第一个问题,但使用HTML select
代替:
<?php
// page1.php
// ...
// create a form element
echo '<form action="page2.php" method="get">';
// create the 'name' input
echo 'Enter the displayed name: <input name="name" placeholder="displayed name"><br />';
// start the dropdown
echo 'Enter the file the link should point to: <select name="file">';
// get all files that should be displayed
$files = scandir(__DIR__);
$files = array_diff($files, array('.', '..'));
foreach ($files as $file) {
// add an option to the dropdown
echo '<option value="' . $file . '">' . $file . '</option>';
}
// close the dropdown and the form
echo '</select>';
// add a submit button to the form
echo '<button type="submit">Submit</button>';
echo '</form>';
// ...
?>
在第二页上,显示的链接:
<?php
// page2.php
// ...
$name = $_GET['name'];
$file = $_GET['file'];
echo '<a href="' . $file . '">' . $name. '</a><br>';
// ...
?>
您是否想要输入一个文件的显示名称或目录中所有文件的名称? – PeterMader
plz解释你在说什么 –
所以,只是为了澄清:在第一页上,用户可以选择显示什么名字,以及链接应该指向哪个文件,使用下拉菜单。在第二页上,显示链接。那是你要的吗? – PeterMader