2014-11-21 105 views
-1
<?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已在服务器上。我想将其更改为我发送的字符串。将字符串写入文件from php

我从一个C#脚本发送到PHP文件的请求,像这样:

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

我得到一个内部服务器错误500

问题是什么?

+0

我认为,file_put_contents()是一个这会产生错误,因为第一个参数应该是根据php手册的文件名...不是你想要放置的新内容。 – 2014-11-21 01:39:51

+0

@ Moch.Rasyid在这种情况下,我怎么才能创建一个文件,并在其中放入字符串? – Ogen 2014-11-21 01:40:49

+0

尝试使用$ my_file或要编写的文件名替换$ new_text,并使用$ new_text切换$ current,因为您要编写传递的任何新文本。 – 2014-11-21 01:42:28

回答

3

内部服务器错误500有发生..如果您收到此那么也许在你的script.Or也许其他原因,任何错误的原因有很多。你可以在上传/ DIR1 /目录检查写权限

你可以检查的.htaccess服务器

上您可以检查阿帕奇的error_log它更好地为你,那么你找出错误。并且顺便说一句,你必须结束第一行语句是

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

,而不是

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

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