我有一个Java小程序,调用这个URL链接到一个PHP脚本,应该写入文件,但没有骰子。我得到一个http 500错误。任何线索?写入文件和搜索文件php
http://127.0.0.1/DBoperations.php?operation=write&UserId=james&Score=10
#DBoperations.php
<?php
$operation = $_REQUEST["operation"]
$UserId = $_REQUEST["Userid"];
$Score = $_REQUEST["Score"];
if (operation =="write"){
write();
}
if (operation =="read"){
read();
}
function write()
{
$myFile = "testsroce.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$UserId - $Score";
fwrite($fh, $stringData);
fclose($fh);
}
function read()
{
$file = new SplFileObject('testscores.txt');
$file->setFlags(SplFileObject::DROP_NEW_LINES);
$match = false;
foreach($file as $line){
if(false !== stripos($line, $UserId)){
$match = true;
break;
}
}
if(true === $match){
echo $file;
} else {
echo "No Match Found";
}
}
?>
是旨在你的 “读” 和 “写” 的文件名有什么不同? –
@Kolink'testsroce'听起来合法xD – TheZ
你的PHP脚本显示什么错误信息?如果需要,打开错误信息。 –