php
PHP File Append and Delete
The PHP append data into file by using a or (a+) mode in fopen() function. Let's see a simple example that appends data into append.txt  file.
append.txt

Welcome To Free Time Learning...!

PHP Append to File

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>
Output (append.txt - After program execution)

Welcome To Free Time Learning...! This is Educational Website.

PHP Delete File

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.

Syntax

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>