2017-05-31 101 views
0

我上次問過如何在ftp-server上傳的文件的網站主體上獲取自動生成的鏈接。 鏈接是這個Link to Code Automatic通過自定義文本鏈接到代碼自動

但我父親希望它不應該顯示文件名。相反,它應該顯示他將在其他頁面上輸入的名稱。

我的主要故事情節是,當我進入該頁面時,它要求我輸入一個名稱,並在<br>後面顯示該名稱,它應該提供ftp-server上文件的下拉菜單,並且要求我選擇我給出的名字。進一步提交時,它會顯示名稱爲i遊戲的文件鏈接。

請幫我解決這個問題,因爲我是PHP和SQL的初學者。

感謝

+0

您是否想要輸入一個文件的顯示名稱或目錄中所有文件的名稱? – PeterMader

+0

plz解釋你在說什麼 –

+0

所以,只是爲了澄清:在第一頁上,用戶可以選擇顯示什麼名字,以及鏈接應該指向哪個文件,使用下拉菜單。在第二頁上,顯示鏈接。那是你要的嗎? – PeterMader

回答

1

第一頁,使用什麼建議在第一個問題,但使用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>'; 
// ... 
?> 
+0

非常感謝你 –

+0

好友,你忘了在page1.php –

+1

添加提交是的,你是對的。我編輯了答案。 – PeterMader