a+
) mode in fopen()
function. Let's see a simple example that appends data into append.txt  file. Welcome To Free Time Learning...!
The PHP fwrite()
function is used to write and append data into file.
<!DOCTYPE html>
<html>
<head>
<title>PHP File Append</title>
</head>
<body>
<?php
$file = fopen('append.txt', 'a');//opens file in append mode
fwrite($file, ' This is ');
fwrite($file, 'Educational Website.');
fclose($file);
echo "File appended successfully";
?>
</body>
</html>
Welcome To Free Time Learning...! This is Educational Website.
In PHP, we can delete any file using unlink()
function. The unlink()
function accepts one argument only: file name. It is similar to UNIX C
unlink()
function.
PHP unlink()
generates E_WARNING level error if file is not deleted. It returns TRUE if file is deleted successfully otherwise FALSE.
unlink ( $filename [, $context ] )
$filename
represents the name of the file to be deleted.
<!DOCTYPE html>
<html>
<head>
<title>PHP File Delete</title>
</head>
<body>
<?php
$del=unlink('delete.txt');
if($del){
echo "Your File deleted successfully";
}else{
echo "Sorry! Not deleted your file";
}
?>
</body>
</html>