unlink() 函数删除文件。
若成功,则返回 true,失败则返回 false。
语法
unlink(filename,context)
参数 描述
filename 必需。规定要删除的文件。
context 可选。规定文件句柄的环境。Context 是可修改流的行为的一套选项。
php教程
$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";
}
?>下面加了判断文件是否存在
$myfile = "./test1.txt";
if (file_exists($myfile)) {
$result=unlink ($myfile);
echo $result;
}
?>
file_exists() 函数检查文件或目录是否存在。
如果指定的文件或目录存在则返回 true,否则返回 false。
语法
file_exists(path)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号