CodesJava

Easy learning with example program codes

PHP Delete File

To delete a file in PHP, unlink() function is used. PHP unlink() function behaves same as UNIX C unlink() function. If the file is deleted successfully, it generates a TRUE value. If the file is not deleted successfully it generates a FALSE value or returns an E_WARNING level error.

Syntax:

bool unlink ( string $filename, context )

Filename: This is a mandatory parameter which specifies the name of the file to be deleted.

Context:   This is an optional parameter which specifies the context (set of options to modify a stream’s behaviour ) of the file handle.

Example:

<!DOCTYPE html>
<html>
<body>
 
<?php      
$deletefile=unlink('phpfile.txt');    
if($deletefile)
{  
echo "File deleted.";    
}
else
{  
echo "Unable to Delete the File.";    
}  
?> 
 
</body>
</html>

Output:

File deleted.
Please follow and like us:
error
Posted in PHP   








Copyright © 2019 CodesJava DMCA.com Protection Status