使用fread()的浏览器输出

时间:2013-12-01 03:05:26

标签: php fread

我是PHP新手,只是尝试编写然后使用以下代码读取html文件:

<?php 
 #Aim: To open , write, save and close a file in PHP

 $fileName =  "myFile.html"; 

 $filePointer = fopen($fileName,"w+"); // Creating a file resource

 $html = '<html>
    <style>
        h1{color:#ee4e91;}
    </style>
    <body>
        <h1>This is some HTml that was written to the File using the 
        file pointer $filePointer in the file that is named as myFile</h1>
    </body>
   </html>
      '; // string to be written to the file in write+ mode*/

  write($filePointer,$html); // writing the string to the file
  fseek($filePointer,0);

  $content = fread($filePointer,filesize($fileName));

  header("Content-Length:".(string)filesize($fileName));
  header("Content-Type:text/html");

  echo $content;

  fclose($filePointer); // closing the file resource
 ?>

我可以在控制台中看到out但在浏览器中失败了。 file_get_contents($ fileName)和readfile($ fileName)工作正常。

问题是什么。如何使用fread()输出到浏览器?

0 个答案:

没有答案