Home  >  Article  >  Backend Development  >  PHP file deletion method_PHP tutorial

PHP file deletion method_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:44:15788browse

The unlink() function deletes files.
Returns true if successful, false if failed.
Syntax
unlink(filename,context)
Parameter Description
filename Required. Specifies the files to be deleted.
context optional. Specifies the environment for a file handle. Context is a set of options that modify the behavior of the stream.

$file_delete = "home/meeta/my.php";

if (unlink($file_delete)) {
echo "The file was deleted successfully. ", "n";
} else {
echo "The specified file could not be deleted. Please try again.", "n";
}
?>The judgment file is added below Does it exist

$myfile = "./test1.txt";
if (file_exists($myfile)) {
$result=unlink ($myfile);
echo $ result;
}
?>
file_exists() function checks whether the file or directory exists.
Returns true if the specified file or directory exists, false otherwise.
Syntax
file_exists(path)


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478761.htmlTechArticleunlink() function deletes files. Returns true if successful, false if failed. Syntax unlink(filename,context) Parameter Description filename Required. Specifies the files to be deleted. con...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn