Home > Article > Backend Development > How to write, delete and copy files in PHP_PHP Tutorial
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:
?
2 3
4 5
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 ?> |
1 2 3 4 | <🎜>$filename = "Test//file.txt";<🎜> <🎜>unlink($filename); //Delete file<🎜> <🎜>?> |
1 2 3 4 5 | <🎜>$filename1 = "Test//file.txt";<🎜> <🎜>$filename2 = "Test//file.bak";<🎜> <🎜>copy($filename1, $filename2); //Copy file<🎜> <🎜>?> |