我有这样的代码在我的脚本:错误与fopen()函数即使它是活跃在配置
$myFile = "1.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $sql);
fclose($fh);
它告诉我无法打开文件! 为什么在我的php.ini配置中allow_url_open为On时出现此错误!我检查这个!
我有这样的代码在我的脚本:错误与fopen()函数即使它是活跃在配置
$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
是一个更安全的权限设置来使用。
'$ sql'是如何定义的? – 2014-10-02 06:58:36
'allow_url_open'不相关,'1.txt'是本地文件系统引用。检查目录/文件权限 – 2014-10-02 07:00:44
$ sql is:'$ sql =“select * from add where compain IN($ compainids)&& publish ='Yes'&& type ='$ type'order by rand()”;' – user1964450 2014-10-02 07:00:47