【发布时间】:2011-01-30 04:29:00
【问题描述】:
我有一个 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['艺术家'], "专辑" => $_GET['专辑'], "文件" => $_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') 或 die('无法打开播放列表!'); 未设置($plist[$_GET['id']]); $plist = 数组值($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 = 数组(“条目” => $plist); $json = json_encode($arr); 回声 $json; } elseif ($_GET['action'] == 'getps') { $plists = array(); if ($handle = opendir('播放列表')) { 而(假!==($播放列表= readdir($handle))) { if ($playlist != “。” && $播放列表!=“..”){ array_push($plists, substr($playlist, 0, strripos($playlist, '.')-1)); } } } else { die('错误:无法打开 播放列表!'); } $arr = 数组(“条目”=>$plists); $json = json_encode($arr);回声 $json; } 别的 { die('错误:没有这样的动作!'); } ?>
它从array_push(... 行的中间开始。
我真的想不出它在做什么。它周围的任何地方都没有echos。有什么想法吗?
【问题讨论】:
标签: php