1.打开文件
//1.文件信息//打开文件$file_path = './file/test.txt';
$fp = fopen($file_path,'r');
if($fp){
$file_info = fstat($fp);
var_dump($file_info);
echo date("Y-m-d H:i:s",$file_info['mtime']) . '
';
echo date("Y-m-d H:i:s",$file_info['atime']) . '
';
echo date("Y-m-d H:i:s",$file_info['ctime']) . '
';
}else{
echo'打开文件失败';
}
fclose($fp);
echo filemtime($file_path) . '
';
echo fileatime($file_path) . '
';
echo filectime($file_path) . '
';
2.读文件
1.文件信息
//打开文件
$file_path = './file/test.txt';
//****第一种读取方式******
/*if(file_exists($file_path)){
$fp = fopen($file_path,'a+');
//读内容,并输出
$con = fread($fp,filesize($file_path));
//在默认情况下,我们得到的内容输出到网页后,不会换行
//因为网页不会识别 \r\n 是换行符,要把 \r\n 替换成
$con = str_replace("\r\n","
",$con);
echo$con;
}else{
echo'文件不存在';
}
fclose($fp);*/
//**********第二种读取方式**********
/*$con = file_get_contents($file_path);
$con = str_replace("\r\n","
",$con);
echo$con;*/
//**********第三种读取方式,循环读取,对付大文件**********
$fp = fopen($file_path,'r');
//我们设置一次读取1024个字节
$buffer = 1024;
//一边读,一边判断是否到达文件末尾
while(!feof($fp))
{
$str = fread($fp,$buffer);
echo$str;
}
fclose($fp);
以上就介绍了83 php文件,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。