php语言文件操作,PHP_File文件操作简单常用函数

php测试文件

header("Content-type:text/html;charest=utf-8");

$fileDir='Upload/File/content.txt';

echo '文件路径:'.$fileDir.'
';

echo '路径目录|dirname():'.dirname($fileDir).'
';

echo '路径文件名|basename():'.basename($fileDir).'
';

echo '文件类型|filetype():'.filetype($fileDir).'
';

echo '文件大小|filesize():'.filesize($fileDir).'
';

echo '文件修改时间|filemtime():'.filemtime($fileDir).'
';

echo '
';

echo '绝对路径|realpath():'.realpath($fileDir).'
';

echo '以数组形式返回路径信息|pathinfo():
';

print_r(pathinfo($fileDir));echo '
';

echo '
';

echo '复制并重命名文件|rename(url01,url02):返回'.copy($fileDir,'./Upload/renameContent.txt').'
';

echo '复制文件|copy(url01,url02):返回'.copy($fileDir,'./Upload/copyContent.txt').'
';

echo '删除文件|unlink(url):返回'.@unlink('./Upload/unlinkContent.txt').'
';

echo '
';

echo '将文件信息以字符串形式读取出来|file_get_contents(url):
';

echo file_get_contents($fileDir).'
';

$putContent='hello word!';

echo '将字符串写入文件,文件不存在自动创建,目录必须存在,|file_put_contents(url,str)返回文件大小:';

echo file_put_contents('./Upload/file_put_contents.txt',$putContent).'
';

?>

php返回结果

文件路径:Upload/File/content.txt

路径目录|dirname():Upload/File

路径文件名|basename():content.txt

文件类型|filetype():file

文件大小|filesize():27

文件修改时间|filemtime():1411488282

绝对路径|realpath():D:\Kuaipan\www\TestPhp\Upload\File\content.txt

以数组形式返回路径信息|pathinfo():

Array ( [dirname] => Upload/File [basename] => content.txt [extension] => txt [filename] => content )

复制并重命名文件|rename(url01,url02):返回1

复制文件|copy(url01,url02):返回1

删除文件|unlink(url):返回

将文件信息以字符串形式读取出来|file_get_contents(url):

hello word! bad word!!!

将字符串写入文件,文件不存在自动创建,目录必须存在,|file_put_contents(url,str)返回文件大小:11

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值