<span><?php
</span><span>if</span>($fp<span>=</span><span><em>fopen</em></span>(<span>"I:/Test/abc.txt"</span>,<span>"r"</span>)){
$file_info<span>=</span><span><em>fstat</em></span>($fp);
<span>echo </span><span>"<pre class="brush:php;toolbar:false">"</span>;
<span><em>print_r</em></span>($file_info);
<span>echo </span><span>" ";
echo "the size of file is -- {$file_info['size']}";
echo "the modify time is -- ".date("Y-m-d H:i:s",$file_info['mtime']);
echo " ";
echo fileatime("I:/Test/abc.txt");
}else{
echo "No Such File Exists";
}
fclose($fp);
$file_path="I:/Test/bbc.txt";
//首先判断文件是否存在;
if(file_exists($file_path)){
//为移植性考虑,强烈建议在用 fopen() 打开文件时总是使用 'b' 标记
$fp=fopen($file_path,"rb");
$con=fread($fp,filesize($file_path));
echo "the content of file is: ";
//转换换行符;
$con=str_replace(PHP_EOL," ",$con);
echo $con;
}else{
echo " no file exists";
}
fclose($fp);
//*********第二种读取方式***********************
//file_get_contents函数会读取整个文件内容(内存足够大),并且会自动关闭指针;
$con=file_get_contents($file_path);
$con=str_replace(PHP_EOL," ",$con);
echo " ".$con;
//**********第三种读取方式,循环读取*********
$fp=fopen($file_path,'rb');
$buffer=10;
$str="";
while(!feof($fp)){
$str.=fread($fp,$buffer);
}
echo $str;
fclose($fp); //以数组形式输出配置文件;对数据库链接有用;
//格式与php.ini相同;
$arr=parse_ini_file("db.ini");
print_r($arr);
The above has introduced PHP: File System, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn