我有一个PHP页面可以执行几个不同的操作,具体取决于GET数据中action
的设置。取而代之,它应该返回一些JSON,但它应该返回代码文档本身的下半部分而不是做任何事情,从行的中间开始。继承了它开始的地方:
...
} elseif ($_GET['action'] == 'addtop') {
if (!isset($_GET['pname']) || !isset($_GET['url']) || !isset($_GET['artist']) || !isset($_GET['album']) || !isset($_GET['file'])) {
die('Error: Incomplete data!');
}
if (!file_exists($_GET['pname'].".txt")) {
die('Error: No such playlist!');
}
$plist = json_decode(file_get_contents($_GET['pname'].".txt"), true);
$fh = fopen($_GET['pname'].".txt", 'w') or die('Could not open playlist!');
array_push($plist, array("artist" => $_GET['artist'], "album" => $_GET['album'], "file" => $_GET['file'], "url" => $_GET['url']));
fwrite($fh,json_encode($plist));
} elseif ($_GET['action'] == 'delfromp') {
...
以下是我访问该页面时的内容:
$ _ GET ['artist'],“album”=> $ _GET ['album'],“file”=> $ _GET ['file'],“url”=> $ _GET [ 'URL'])); FWRITE($ FH,json_encode($的plist)); } elseif($ _GET ['action'] =='delfromp') {if(!isset($ _ GET ['pname'])|| !isset($ _ GET ['id'])){die('错误: 数据不完整!');如果 (!file_exists($ _ GET [ 'PNAME']。 “TXT”)) {die('错误:没有这样的播放列表!'); } $ plist = json_decode(的file_get_contents($ _ GET [ 'PNAME'] “TXT”), 真正); $ fh = fopen($ _ GET ['pname']。“。txt”,'w')或 死('无法打开播放列表!'); 未设置($的plist [$ _ GET [ '身份证']); $ plist = array_values($的plist); FWRITE($ FH,json_encode($的plist)); } elseif($ _GET ['action'] =='readp'){ 如果 (!file_exists($ _ GET [ 'PNAME']。 “TXT”)) {die('错误:没有这样的播放列表!'); } $ plist = json_decode(的file_get_contents($ _ GET [ 'PNAME'] “TXT”), 真正); $ arr = array(“entries”=> $的plist); $ json = json_encode($ arr); echo $ json; } elseif($ _GET ['action'] =='getps'){$ plists = array(); if($ handle = opendir('播放列表')){ while(假!==($ playlist = readdir($ handle))){if($ playlist!= “” &安培;&安培; $ playlist!=“..”){ array_push($ plists,substr($ playlist, 0,strripos($ playlist,'。') - 1)); }}} else {die('错误:不能打开 播放列表')!; } $ arr = 阵列( “条目”=> $的Plist); $ json = json_encode($ ARR); echo $ json;其他 {die('错误:没有这样的行动!'); }?>
它从array_push(...
行的中间开始。
我真的想不起它在做什么。围绕它的地方没有echo
。有什么想法吗?
答案 0 :(得分:2)
看起来=>
正在关闭您的PHP代码。你有短标签吗?或某种自定义标签?