![](/img/trans.png)
[英]How can I delete particular image in the database and folder inside one action in PHP?
[英]How can I delete a php file inside a folder?
我在一個文件夾( folder/abc.php
)中有一個php文件,在完成某些任務並且不再需要將該文件保留在該文件夾中之后,我想清理並刪除該文件。 刪除該文件的正確功能或代碼是什么? 謝謝,
<?php
$filename = './test/abc.php';
if (file_exists($filename)) {
echo "Deleting $filename";
unlink($filename);
} else {
echo "The file $filename does not exist";
}
?>
參考: http : //php.net/manual/en/function.file-exists.php&http : //php.net/manual/en/function.unlink.php
unlink('your_file_path');
。 確保您的腳本具有特定權限。
您可以通過以下方式執行此操作:
$path = $_SERVER['DOCUMENT_ROOT'].'folder/abc.php';
if (file_exists($path)) { // Check if file exists in folder or not?
unlink($path);
}
else{
echo "File does not exists in the directory!";
}
嘗試這個
$path = $_SERVER['DOCUMENT_ROOT'].'/test/abc.php';
unlink($path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.