unlink()函數(shù)可以刪除文件,成功時(shí)返回true,失敗時(shí)返回false。
bool unlink ( string $filename [, resource $context ] )
該函數(shù)可以刪除文件名,與Unix C unlink()函數(shù)類似。
<?php
$file = "/PhpProject/php/sample.txt";
if(!unlink($file)) {
echo ("刪除 $file 時(shí)出錯(cuò)");
} else {
echo ("刪除 $file 成功");
}
?>輸出結(jié)果
刪除 /PhpProject/php/sample.txt 成功
<?php
$fh = fopen("/PhpProject/test.html", "a");
fwrite($fh, "<h1> Hello world! </h1>");
fclose($fh);
unlink("/PhpProject1/test.html");
?>輸出結(jié)果
file deleted succcessfully