欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php写入、删除与复制文件的方法

程序员文章站 2022-04-12 16:52:31
本文实例讲述了php写入、删除与复制文件的方法。分享给大家供大家参考。具体如下: 1. 写入:

本文实例讲述了php写入、删除与复制文件的方法。分享给大家供大家参考。具体如下:

1. 写入:

<?php 
$filename = "test//file.txt"; 
$file = fopen($filename, "w"); //以写模式打开文件 
fwrite($file, "hello, world!/n"); //写入第一行 
fwrite($file, "this is a test!/n"); //写入第二行 
fclose($file); //关闭文件 
?> 

2. 删除:

<?php 
$filename = "test//file.txt"; 
unlink($filename); //删除文件 
?> 

3.复制:

<?php 
$filename1 = "test//file.txt"; 
$filename2 = "test//file.bak"; 
copy($filename1, $filename2); //复制文件 
?>

希望本文所述对大家的php程序设计有所帮助。