php刪除文件的方法:可以利用unlink()函數(shù)來刪除文件。如果刪除成功,該函數(shù)返回true;如果刪除失敗,則返回false,具體使用方法如:【if (!unlink($file)){false}else{true}】。
unlink() 函數(shù)刪除文件。如果成功,該函數(shù)返回 TRUE。如果失敗,則返回 FALSE。
(推薦教程:php圖文教程)
語法:
unlink(filename,context)
參數(shù):
-
filename 必需。規(guī)定要刪除的文件。
-
context 可選。規(guī)定文件句柄的環(huán)境。context 是一套可以修改流的行為的選項。
(視頻教程推薦:編程入門)
代碼實現(xiàn):
<?php /** * [$file 文件刪除執(zhí)行] * @var string */ $file = "test.txt"; if (!unlink($file)) { echo ("Error deleting $file"); } else { echo ("刪除成功 $file"); } ?>