Notice: Constant WP_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 107

Notice: Constant WP_MAX_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 108
PHP Delete File - CodesJava

CodesJava

Easy learning with example program codes

PHP Delete File


Notice: Undefined variable: footnotelist in /home/javawith/public_html/codesjava.com/wp-content/plugins/latex2html/inc/core.php on line 475

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