这是我的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
位于服务器上的同一目录中
答案 0 :(得分:0)
如果您的文件直接位于htdocs下:
$file = $_SERVER['DOCUMENT_ROOT'] . '/myTextFile.txt';