获取文件信息:
//打开文件
$file_path = "test.txt";
//获取文件信息
if($fp=fopen($file_path,"r")){
$file_info = fstat($fp);
echo "<pre class="brush:php;toolbar:false;">";
print_r($file_info);
echo "读取文件信息:
<?php
//读取文件
$file_path = "test.txt";
//先判断文件是否存在
if(file_exists($file_path)){
$fp = fopen($file_path,"a+");
//读取内容并且输出
$content = fread($fp,filesize($file_path));
echo "文件内容是:<br/>";
$content = str_replace("\r\n", "<br/>", $content);
echo $content;
}else{
echo "文件不存在";
}
//关闭文件
fclose($fp);
?>读取文件信息的简单方式:
<span style="font-size:18px;"><?php
// //读取文件
$file_path = "test.txt";
$contents = file_get_contents($file_path);
$contents = str_replace("\r\n", "<br/>", $contents);
echo $contents;
?></span>以上就介绍了php 读写文件,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号