Home  >  Article  >  Backend Development  >  How to write, delete and copy files in PHP_PHP Tutorial

How to write, delete and copy files in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 09:49:13887browse

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

$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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn