php文件系统

一,文件读取写入

1,file_get_contents读取

<?php
$filenam="hello.php";
$filestring=file_get_contents($filenam); //打开html文件就会直接执行
echo $filestring;
?>

2,readfile读取文件

<?php
readfile('hello.php')
?>

3,fopen,fread/fwrite,fclose读取/写入文件

(1)读取文件
<?php
$file=fopen('hello.php','r');
$rfile=fread($file,filesize("hello.html")); //  两个参数,读取所有
echo "$rfile";
fclose($file);
?>
(2)写入文件

<?php
$file=fopen('hello.php','w');
$wfile=fwrite($file,"hello");
fclose($file);
print $wfile; // 有多少字节被写入了
?>

4,file_put_contents写入文件

<?php
// 写入文件返回写入字节数
$data="你好啊,php";
$numbates=file_put_contents('aa.txt',$data);
echo'==============='.'<br>';
echo "$numbates";
?>

5,创建临时文件

使用完后删除,不需要维护文件删除状态

<?php
$handle=tmpfile();  //创建临时文件
fwrite($handle,"deaff"); //向临时文件中写入 
?>

二,文件其它操作

1,重命名文件

rename('hello.php','helloword.php'); //把hello.php文件名改为helloword.php

2,复制文件

copy('hello.php','hello_copy.php');

3,删除文件

unlink('hello_copy.php');

三,文件属性

1,检测文件是否存在:

file_exists

2,检测文件是否可读/写/执行

 is_file() 是否是文件
 is_readable($filename) 文件是否可读
 is_writeable($filename) 是否可写
 is_writable($filename)  是否可写返回1,0
 is_executable($filename) 是否可执行
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值