Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

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

Comments

comments