fopen()在配置中处于活动状态时出错


Error with fopen() even though it is active in configuration

我的脚本中有以下代码:

$myFile = "1.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $sql);
fclose($fh);

它显示我无法打开文件!为什么在我的php.ini配置中allow_url_open为On时会出现此错误!我检查一下!

首先确保1.txt已经存在,并且为文件和文件夹设置了正确的写入权限。文件夹通常设置为0755

您可以使用chmod命令通过FTP执行此操作,也可以在代码中实现它。

尝试将chmod添加到代码中:

$myFile = "1.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
chmod($myFile,0644);
fwrite($fh, $sql);
fclose($fh);

您也可以尝试将0644更改为0777,但使用0644是更安全的权限设置。

您似乎没有从目录访问文件的权限。

您需要使用chmod对该文件授予适当的权限。

您可以在此处查看chmod权限规则