从php写一个字符串到一个文件

时间:2014-11-21 01:35:49

标签: c# php

<?php
$my_file = "uploads/dir1/myText.txt"

$current = file_get_contents($my_file);

$new_text = http_get_request_body();

file_put_contents($new_text, $current);
?>

$myText.txt已在服务器上。我想将其更改为我发送的字符串。

我正在从C#脚本向php文件发送请求,如下所示:

webClient.UploadString(linkToMyWebsitesUploadPHPFile, "POST", "here is my new text");

我收到内部服务器错误500。

有什么问题?

1 个答案:

答案 0 :(得分:2)

内部服务器错误500它有很多原因发生..如果你得到这个,那么你的脚本可能有任何错误。或许其他原因......你可以检查上传中的写入权限 dir1 /目录。

您可以在服务器上检查.htaccess

您可以更好地检查Apache error_log ,然后找出错误。顺便说一句,你必须结束第一行语句

$my_file = "uploads/dir1/myText.txt";

而不是

$my_file = "uploads/dir1/myText.txt"

之后你必须检查file-get-contents 然后http-get-request-body