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