PHP fopen功能无法正常工作

问题描述 投票:0回答:1

我正在尝试在我的计算机上开发一些网页,它一直工作正常,直到我尝试使用fopen函数,它返回FALSE eveytime。 .php文件位于/ var / www / html /目录中,我要打开的文件也在同一个目录中,但我也尝试在/ home / myusername /目录中打开一个文件而它没有工作以及。

我在其他帖子中看到它可能是权限,我做了所建议的内容,但无论如何它都不起作用。

我的代码:

    ...
$file = fopen("/home/msantos/direction.txt", w);
if ($file == FALSE) {
    echo "error fopen <br>";
}    
if(fwrite($file, "teste") == FALSE)
{
    echo "error fwrite";
}

结果总是:“错误fopen”。显然,因为fopen不起作用我也得到:“错误fwrite”。

有谁知道我做错了什么或我要做些什么来使它工作?

编辑:我在其中一条评论中建议使用error_get_last()并输出以下内容:

Array ( [type] => 2 [message] => fopen(/home/msantos/direction.txt): failed to open stream: Permission denied [file] => /var/www/html/teste.php [line] => 29 ) 

所以它似乎确实是一个许可问题。我需要做些什么来使它工作?

file php webserver
1个回答
2
投票

自从我使用PHP以来已经很长时间了,但我相信fopen()需要为模式提供一个字符串/ char参数。从而:

$file = fopen("/home/msantos/direction.txt", w);  

$file = fopen("/home/msantos/direction.txt", 'w');  

Source

© www.soinside.com 2019 - 2024. All rights reserved.