2017-02-05 102 views
-1

我遇到了PHP写入.txt文件的问题。允许PHP写入.txt文件

此代码工作正常时,PHP想读“R”

<?php 
    $myfile = fopen("chat.txt", "r") or die("Unable to open file!"); 
    echo fread($myfile,filesize("chat.txt")); 
    fclose($myfile); 
?> 

当它被设置为写“W”或追加“一”

<?php 
    $myfile = fopen("chat.txt", "w") or die("Unable to open file!"); 

    fclose($myfile); 
?> 

此它不工作给我500内部服务器错误

我用的Go Daddy顺便说

我该如何解决这个问题

下面是一个错误消息我

警告:的fopen(chat.txt)[function.fopen]:未能打开流: 权限在 ģ否认:\ PleskVhosts \ johnnywaity.com \ httpdocs \ beta \ Chat \ process.php在线 2无法打开文件!

+0

想这是一个权限问题。 – Shiping

+0

它在错误日志中说了什么? –

回答

-1

fwrite()写入打开的文件。你正在使用fread()。

进行此更改

<?php 
    $myfile = fopen("chat.txt", "r") or die("Unable to open file!"); 
    echo fwrite($myfile,filesize("chat.txt")); 
    fclose($myfile); 
?> 
+0

你不能'fwrite()'到''fopen()''用'r'方式编辑的文件。 –