Home > Backend Development > PHP Tutorial > PHP unlink function deletes a file program code_PHP tutorial

PHP unlink function deletes a file program code_PHP tutorial

WBOY
Release: 2016-07-13 17:15:28
Original
962 people have browsed it

In PHP, if we want to delete a specified file, we can use the unlink function to achieve this. Below, I will give you a detailed introduction to the specific method of the unlink function to delete a specified file. Friends who need to know more can refer to it.

The unlink() function deletes files.

Returns true if successful, false if failed.

The code is as follows
 代码如下 复制代码

unlink("test.txt");
?>

Copy code

 代码如下 复制代码

$file = "test.txt";if (!unlink($file)) {
echo ("Error deleting $file"); }else {
echo ("Deleted $file"); }
?>

unlink("test.txt");

?>
 代码如下 复制代码

$file = "test.txt";
if(unlink($file))
{
echo "文件 $file 删除成功!";
}
else
{
echo "文件 $file 删除失败!";
}
?>


Example

The code is as follows

Copy code
 代码如下 复制代码

$myfile = “./test1.txt”;
if (file_exists($myfile)) {
$result=unlink ($myfile);
echo $result;
}
?>

$file = "test.txt";if (!unlink($file)) {

echo ("Error deleting $file"); }else {

echo ("Deleted $file"); }

?>

 代码如下 复制代码

$dirname = 'testdir';
if (rmdir( $dirname )) {
echo "目录 $dirname 删除成功";
} else {
echo "目录 $dirname 删除失败";
}
?>

Add judgment
The code is as follows
Copy code

$file = "test.txt"; { echo "File $file deleted successfully!"; } else { echo "File $file deletion failed!"; } ?>

Output result: The file test.txt was deleted successfully! The following is added to determine whether the file exists:
The code is as follows Copy code
<🎜>$myfile = “./test1.txt”;<🎜> if (file_exists($myfile)) {<🎜> $result=unlink ($myfile);<🎜> echo $result;<🎜> }<🎜> ?> The rmdir() function deletes a directory and returns TRUE if successful, otherwise it returns FALSE. Syntax: bool rmdir( string dirname ) Example:
The code is as follows Copy code
$dirname = 'testdir';<🎜> if (rmdir( $dirname )) {<🎜> echo "Directory $dirname deleted successfully";<🎜> } else {<🎜> echo "Failed to delete directory $dirname";<🎜> }<🎜> ?> http://www.bkjia.com/PHPjc/628815.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/628815.htmlTechArticleIn php, if we want to delete a specified file, we can use the unlink function to achieve this. I will give you a detailed introduction below. The specific method of unlink function to delete a specified file, if needed...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template