php第一種特殊類型-資源報(bào)錯問題
<?php?
//首先采用“fopen”函數(shù)打開文件,得到返回值的就是資源類型。
$file_handle = fopen("/data/webroot/resource/php/f.txt","r");
if ($file_handle){
? ? //接著采用while循環(huán)(后面語言結(jié)構(gòu)語句中的循環(huán)結(jié)構(gòu)會詳細(xì)介紹)一行行地讀取文件,然后輸出每行的文字
? ? while (!feof($file_handle)) { //判斷是否到最后一行
? ? ? ? $line = fgets($file_handle); //讀取一行文本
? ? ? ? echo $line; //輸出一行文本
? ? ? ? echo "<br />"; //換行
? ? }
}
fclose($file_handle);//關(guān)閉文件
?>
報(bào)錯內(nèi)容: Warning:?fopen(/webroot/resource/php/f.txt):?failed?to?open?stream:?No?such?file?or?directory?in?/54/754/Kkgk/index.php?on?line?3 Warning:?fclose()?expects?parameter?1?to?be?resource,?boolean?given?in?/54/754/Kkgk/index.php?on?line?12
2017-03-27
mooc的服務(wù)器上沒提供這個文件。建議在本機(jī)上嘗試
2017-03-27
上面沒有文件,可以打開自己電腦的文件試試