【发布时间】:2015-02-01 18:28:47
【问题描述】:
这是我的 C# 代码:
WebClient myClient = new WebClient();
NameValueCollection inputs = new NameValueCollection();
inputs.Add("decrement", "true");
System.Uri uri = new System.Uri ("http://myserver/myPHP.php");
myClient.UploadValuesAsync (uri, "POST", inputs);
这是我在服务器上的myPHP.php 文件:
if($_POST['decrement'] == "true") {
$file = './myTextFile.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
}
txt 文件没有被写入,为什么不呢?
注意:myPHP.php 和 myTextFile.txt 在服务器上的同一目录中
【问题讨论】:
-
可能是因为 $_POST['decrement'] 不 == "true"
-
但我将它设置在 C# 的键值对中。请与我平起平坐,我没有php经验。
-
或者因为使用
./文件路径不起作用。您需要使用一个函数来为您提供服务器的 htdocs 路径。
标签: c# php text-files server