Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-显示.txt内容的下拉列表_Php_Drop Down Menu_File Get Contents - Fatal编程技术网

PHP-显示.txt内容的下拉列表

PHP-显示.txt内容的下拉列表,php,drop-down-menu,file-get-contents,Php,Drop Down Menu,File Get Contents,我有一个表格,它有一个歌曲标题的下拉列表。我想能够在歌曲标题和歌词之一点击被加载在同一页上。歌词包含在名为“歌词”的文件夹中的.txt文件中 例如: 下拉列表包含: 歌曲1 歌曲2 歌曲3 等等 当用户单击歌曲时,相应的.txt文件的内容将显示在同一页面上。有什么想法吗?这是一个快速的解决方案,但非常不安全,仅作为示例,如何实现,但不应: <? //否则 ?> 在梅尼乌: <a href="songs.php?songName=song1">song1</a&g

我有一个表格,它有一个歌曲标题的下拉列表。我想能够在歌曲标题和歌词之一点击被加载在同一页上。歌词包含在名为“歌词”的文件夹中的.txt文件中

例如:

下拉列表包含: 歌曲1 歌曲2 歌曲3 等等


当用户单击歌曲时,相应的.txt文件的内容将显示在同一页面上。有什么想法吗?

这是一个快速的解决方案,但非常不安全,仅作为示例,如何实现,但不应:

<?
//否则

?>
在梅尼乌:

<a href="songs.php?songName=song1">song1</a>



祝你好运

使用JQuery会更容易:

<a href="somefile.txt" class="link">Song 1</a>
<pre id="lyrics">
</pre>

<script>
$(function(){
   $('.link').click(function(){
     $.get(this.href,null,function(lyrics){
         $('#lyrics').html(lyrics);
         return false;
     });
   });
});
</script>

$(函数(){
$('.link')。单击(函数(){
$.get(this.href,null,函数(歌词){
$(“#歌词”).html(歌词);
返回false;
});
});
});

如果您有一个歌曲列表,并且您使用了一个简单的命名约定,那么在您考虑使用file\u GET\u内容之前,将其用作白名单来检查GET值是否被允许

file_get_contents $song=$_获得['song']; $file='/lysts/'$歌曲。txt'; $songs=数组(‘帮助’、‘她爱你’、‘黄色潜水艇’); //作为双重检查,请查看该文件是否也存在 如果(在数组中($song,$songs)&&file_存在($file)){ 回显文件\u获取\u内容($file); } 如果您很聪明,还可以重用相同的$songs数组来创建下拉列表


然后,如果你把它保存在数据库中,你可能会认为“slug”“yellow subside”是一个理想的私钥,但请不要让我开始…

好评论。尽管他是用PHP来要求的。
<a href="somefile.txt" class="link">Song 1</a>
<pre id="lyrics">
</pre>

<script>
$(function(){
   $('.link').click(function(){
     $.get(this.href,null,function(lyrics){
         $('#lyrics').html(lyrics);
         return false;
     });
   });
});
</script>
file_get_contents $song = $_GET['song'] ; $file = '/Lyrics/' . $song . '.txt' ; $songs = array( 'help', 'she-loves-you', 'yellow-submarine' ); // as a double check see if the file exists too if( in_array( $song, $songs ) && file_exists( $file ) ) { echo file_get_contents( $file ); }