PHP Tutorial
You can append data into file by using a or a+ mode in fopen() function.
To append data into file, you need to use 'a' mode.
The PHP fwrite() function is used to write and append data into file.
<?php
$fp = fopen('file2.txt', 'a');//opens file in append mode
fwrite($fp, 'This is an example of appending to file. ');
fclose($fp);
echo "File written successfully";
?>
This will produce the following result −
Open file2.txt to see the difference.
Code Always To Become Best Programmer.
This is an example of appending to file.
In PHP, we can delete any file using unlink() function.
The unlink() function accepts one argument only: file name.
bool unlink ( string $filename [, resource $context ] )
$filename represents the name of the file to be deleted.
Lets put this into example.
<?php
$status=unlink('file2.txt');
if($status){
echo "File deleted successfully.";
}else{
echo " File not deleted.";
}
?>