我的脚本中有以下代码:
$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权限规则