close[x]


PHP

PHP-Home PHP-Environment Setup PHP-Syntax PHP-Run PHP in XAMPP PHP-Variable PHP-Comment PHP-Datatype PHP-String PHP-Operators PHP-Decision PHP-loop PHP-Get/Post PHP-Do While loop PHP-While loop PHP-For loop PHP-Foreach loop PHP-Array PHP-Multidimensional Arrays PHP-Associative Arrays PHP-Indexed Arrays PHP-Function PHP-Cookies. PHP-Session PHP-File upload PHP-Email PHP-Data & Time PHP-Include & Require PHP-Error PHP-File I/O PHP-Read File PHP-Write File PHP-Append & Delete File PHP-Filter PHP-Form Validation PHP-MySQl PHP-XML PHP-AJAX



learncodehere.com




PHP - Append to File

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.

PHP - Append to File - fwrite()

The PHP fwrite() function is used to write and append data into file.

Example : Append to 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.

Result


 Code Always To Become Best Programmer.
 This is an example of appending to file. 


PHP - Delete File

In PHP, we can delete any file using unlink() function.

The unlink() function accepts one argument only: file name.

Syntax : Delete File


 bool unlink ( string $filename [, resource $context ] )  

$filename represents the name of the file to be deleted.

Lets put this into example.

Example : Deletes File


<?php  
$status=unlink('file2.txt');    
if($status){  
echo "File deleted successfully.";    
}else{  
echo " File not deleted.";    
}   
 ?>