● 讀文件 首先是一個文件看能不能讀取(權(quán)限問題),或者存在不,我們可以用is_readable函數(shù)獲取信息.: <?php $file = 'dirlist.php'; if (is_readable($file) == false) { die('文件不存在或者無法讀取'); } else { echo '存在'; } ?> 判斷文件存在的函數(shù)還有file_exists(下面演示),但是這個顯然無is_readable全面.,當(dāng)一個文件存在的話可以用 <?php $file = "filelist.php"; if (file_exists($file) == false) { die('文件不存在'); } $data = file_get_contents($file); echo htmlentities($data); ?> 但是file_get_contents函數(shù)在較低版本上不支持,可以先創(chuàng)建文件的一個句柄,然后用指針讀取全部: $fso = fopen($cacheFile, 'r'); $data = fread($fso, filesize($cacheFile)); fclose($fso); 還有一種方式,可以讀取二進(jìn)制的文件: $data = implode('', file($file)); 本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/fkedwgwy/archive/2008/06/04/2511639.aspx
發(fā)表評論