2017-05-31 46 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