在PHP中,有多种方法可以删除文件,包括:
$file = 'path/to/file.txt';
if (unlink($file)) {
echo '文件删除成功';
} else {
echo '文件删除失败';
}
$file = 'path/to/file.txt';
if (file_exists($file)) {
if (unlink($file)) {
echo '文件删除成功';
} else {
echo '文件删除失败';
}
} else {
echo '文件不存在';
}
$file = 'path/to/file.txt';
if (is_file($file)) {
if (unlink($file)) {
echo '文件删除成功';
} else {
echo '文件删除失败';
}
} else {
echo '文件不存在';
}
$file = 'path/to/file.txt';
if (file_exists($file) && is_writable($file)) {
if (unlink($file)) {
echo '文件删除成功';
} else {
echo '文件删除失败';
}
} else {
echo '文件不存在或不可写';
}
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:PHP中删除文件的方法有哪些