How to write, delete and copy files in php
This article explains how to write, delete and copy files in php. Share it with everyone for your reference. The details are as follows:
1. Write:
?
1
2
3
4
5
6
7
|
$filename = "Test//file.txt";
$file = fopen($filename, "w"); //以写模式打开文件
fwrite($file, "Hello, world!/n"); //写入第一行
fwrite($file, "This is a test!/n"); //写入第二行
fclose($file); //关闭文件
?>
|
1
2
3
1
2
3
4
|
$filename = "Test//file.txt";
unlink($filename); //删除文件
?>
|
4
5
1
2
3
4
5
|
$filename1 = "Test//file.txt";
$filename2 = "Test//file.bak";
copy($filename1, $filename2); //复制文件
?>
|
6
7
|
$filename = "Test//file.txt";
$file = fopen($filename, "w"); //Open the file in write mode
fwrite($file, "Hello, world!/n"); //Write the first line
fwrite($file, "This is a test!/n"); //Write the second line
fclose($file); //Close the file
?>
|
2. Delete:
1
2
3
4
|
<🎜>$filename = "Test//file.txt";<🎜>
<🎜>unlink($filename); //Delete file<🎜>
<🎜>?>
|
3. Copy:
?
1
2
3
4
5
|
<🎜>$filename1 = "Test//file.txt";<🎜>
<🎜>$filename2 = "Test//file.bak";<🎜>
<🎜>copy($filename1, $filename2); //Copy file<🎜>
<🎜>?>
|
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/1020287.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1020287.htmlTechArticleHow to write, delete and copy files in php. This article explains how to write, delete and copy files in php. . Share it with everyone for your reference. The details are as follows: 1. Write: ? 1 2 3 4...