file 读取方式

<?php

//文件变量
$file_path="test.txt";

if(file_exists($file_path)){
//打开文件
$fp=fopen($file_path,"a+");
//读内容,输入 *****第一种读取方式
$conn=fread($fp, filesize($file_path));
//echo "文件的内容是".$conn."<br/>";
//在默认情况下,得到的内容不会换行
//不认 是换行符,只认<br/>
$conn=str_replace(" ","<br/>",$conn);
echo $conn;
}else{
echo "文件不存在";
}
// fclose($fp);

//*********第二种读取方式********

$con=file_get_contents($file_path);
$con=str_replace(" ","<br/>",$conn);
echo $con;


//********第三种读取方式 循环读取(对付大文件)
if(file_exists($file_path)){

$fp=fopen($file_path,"a+");

//设置一次读取多少个字节
$buffer=1024;
$str="";
//一边读,一边判断是否达到达文件的末尾
while (!feof($fp)){
//读
$str=fread($fp, $buffer);
$str=str_replace(" ","<br/>",$str);
echo $str;
}
}
echo filegroup("test.txt");
echo fileinode("test.txt");
echo fileperms("test.txt");
clearstatcache("test.txt");
fclose($fp);

?>

原文地址:https://www.cnblogs.com/kevinggk/p/6589767.html