//讀取不到文件,報錯了
<?php?
//首先采用“fopen”函數打開文件,得到返回值的就是資源類型。
$file_handle = fopen("/data/webroot/resource/php/f.txt","r");//讀取不到文件,報錯了
//PHP Warning:? fopen(/data/webroot/resource/php/f.txt): failed to open stream: No such file or directory in index.php on line 3
//PHP Warning:? fclose() expects parameter 1 to be resource, boolean given in index.php on line 12
if ($file_handle){
? ? //接著采用while循環(后面語言結構語句中的循環結構會詳細介紹)一行行地讀取文件,然后輸出每行的文字
? ? while (!feof($file_handle)) { //判斷是否到最后一行
? ? ? ? $line = fgets($file_handle); //讀取一行文本
? ? ? ? echo $line; //輸出一行文本
? ? ? ? echo "<br />"; //換行
? ? }
}
fclose($file_handle);//關閉文件
?>
2021-09-18
路徑不對
常見錯誤:
1路徑不對
2文件不存在
3沒有權限