我嘗試刪除文件,該文件是在/etc/scripts/
PHP - 不能刪除文件
首先,我創建了一個演示文件:
echo "test1234" > test.log
-RW-R - R-- 1個根根7月5日13:15 3 test.log中
現在,我嘗試使用PHP來刪除它:
deleteFile();
function deleteFile()
{
$file = "/etc/scripts/test.log";
if (is_file($file)) {
chmod($file, 0777);
if (unlink($file)) {
return "File '$file' deleted.";
} else {
return "File '$file' could not be deleted.";
}
} else {
return "$file is not a file!";
}
}
但我得到File '/etc/scripts/test.log' could not be deleted.
作爲迴應;
我也對該文件執行了chmod 777 test.log
,結果相同。
檢查你的用戶自己的操作與否?這個操作可能被允許到'root'上。 – urfusion
你可能沒有正確定位文件,可能是一些路徑問題。做'var_dump(file_exists($ file));'首先,在'deleteFile'函數 – samayo
裏面你是否以控制檯的root身份執行chmod 777?這樣做從PHP不會改變任何東西(除非你已經設法讓PHP以root身份運行) – rypskar