in
The function to determine the existence of a file also includes file_exists (demonstrated below), but this is obviously not as comprehensive as is_readable. When a file If it exists, you can use
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span> ?php </span></span></li><li><span>$</span><span class="attribute">file</span><span> = </span><span class="attribute-value">"filelist.php"</span><span>; </span></li><li class="alt"><span>if (file_exists($file) == false) { </span></li><li><span>die('文件不存在'); </span></li><li class="alt"><span>} </span></li><li><span>$</span><span class="attribute">data</span><span> = </span><span class="attribute-value">file_get_contents</span><span>($file); </span></li><li class="alt"><span>echo htmlentities($data); </span></li><li><span class="tag">?></span><span> </span></span></li> <li class="alt"><span> </span></li> </ol>
. However, the file_get_contents function is not supported in lower versions. You can first create a handle to the file, and then use the pointer to read all :
$fso = fopen($cacheFile, 'r');
$data = fread($fso, filesize($cacheFile));
fclose($fso);
There is another way to read binary files:
$data = implode('', file($file));