Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';不要用PHP打开文件_Php - Fatal编程技术网

Can';不要用PHP打开文件

Can';不要用PHP打开文件,php,Php,我正在尝试打开具有写访问权限的文件: $myFile = "all.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); 我的浏览器正在回吐: 无法打开文件 我已经尝试使用chmod-r777来指定这个PHP文件所在的文件夹以及$myFile(一个文本文件)所在的文件夹。还有什么问题 当我打开错误报告时,会出现权限错误。当我执行ls-la all.txt时,我得到-rwx------1 Myname staff 0 Nov 8 1

我正在尝试打开具有写访问权限的文件:

$myFile = "all.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
我的浏览器正在回吐:

无法打开文件

我已经尝试使用chmod-r777来指定这个PHP文件所在的文件夹以及$myFile(一个文本文件)所在的文件夹。还有什么问题


当我打开错误报告时,会出现权限错误。当我执行
ls-la all.txt
时,我得到
-rwx------1 Myname staff 0 Nov 8 15:11 all.txt
如果脚本是从其他目录启动的,请尝试从完整目录打开文件

例如:

$myFile = '/path/to/myFile.txt';
if (!file_exists($myFile)) {
  print 'File not found';
}
else if(!$fh = fopen($myFile, 'w')) {
  print 'Can\'t open file';
}
else {
  print 'Success open file';
}

这两个文件都在同一目录中吗?您应该从
fopen
收到一条警告,是的,它们在同一目录中。如何获取该错误消息?添加
错误报告(E\u ALL);ini_集('display_errors','1')到脚本顶部此返回“无法打开文件”请检查错误<代码>ini\U集合(“显示错误”,1);错误报告(E_全部)是的,一旦我添加了这些,它就是一个权限错误。如果它是一个权限错误,谷歌chmod