PHP - fread()函数

时间:2016-07-13 03:19:08

标签: php

我有简单的文件......我从w3schools获得了代码

当我尝试执行代码时

fread()函数不返回任何内容

first.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$file = fopen("test.php","r");
fread($file,filesize("test.php"));

?>

test.php的

<?php 
echo "Hello world"; 
?>

当我打开localhost/first.php

结果是空白页

1 个答案:

答案 0 :(得分:0)

您永远不会捕获您阅读的内容以在页面上显示它。做

$contents = fread(...);
if($contents===false):
    //there was an error
else:
    echo $contents;
endif;