第一頁,使用什麼建議在第一個問題,但使用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