PHP Delete File PHP

PHP Delete File  

PHP Delete File

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

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

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

PHP Delete File Example

  1. <?php      
  2. $status=unlink('data.txt');    
  3. if($status){  
  4. echo "File deleted successfully";    
  5. }else{  
  6. echo "Sorry!";    
  7. }  
  8. ?>  

Output

File deleted successfully

Download free E-book of PHP


#askProgrammers
Learn Programming for Free


Join Programmers Community on Telegram


Talk with Experienced Programmers


Just drop a message, we will solve your queries