Delete a file Using Php
In PHP, we can use unlink() function to delete a file from given folder/path.
unlink() returns boolean value. It returns TRUE on success and FALSE on failure.
Syntax:
unlink($targetFilename);
Arg:
1. $targetFilename is required.
if we missed/give wrong file name it throw the warning error like-
'Warning: unlink(test.txt): No such file or directory in /var/www/filehandling/deletefile.php on line 10'
Example:
<?php
/*
* Created By: Evon Tech
* Date:1/4/2015
*/
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
$targetFilename = "test.txt";
if (unlink($targetFilename)) {
echo ("Deleted $targetFilename");
} else {
echo ("Failed");
}
?>
0 Comment(s)