fopen($ myFile,"r")为什么我返回NULL

sop*_*hie 1 php file

$fp = fopen( $myFile, "r" );

//if echo $fp => I GOT NULL 

fclose($fp);
Run Code Online (Sandbox Code Playgroud)

但是,如果我这样做,file_get_contents($myFile);我得到了该文件的字符串数据.

我的文件(fedora os)

-rw-r--r-- 1 apache appli 104  2 nov.  12:54 12_62_xxx.log
Run Code Online (Sandbox Code Playgroud)

Lyt*_*yth 6

$fp是一个句柄,它不是文件中的一些真实数据.您可以在其他功能中使用此句柄,例如freadfclose. file_get_contents在内部打开文件,读取文件,关闭文件并返回字符串.这就是为什么当你打印最后一个的结果时,你得到文件的内容.

试着echo fgets($fp)看看你得到了什么.