Posts tagged ‘dreamhost’

錯誤使用者’dhapache’

Dreamhost有時會無法刪除檔案和資料夾,可能是因為使用者變成 ‘dhapache’ ,其中之一的原因是若沒有設定PHP as CGI,執行某些PHP script時就會變這樣,但也有不知名的原因。

這裡提供一個script可以清理這些檔案,將 $startpath 設為要掃除的資料夾即可,記得使用前先備份。

<?php
$startpath = “/home/.raggs/DH_USERNAME/PATH/PATH/";

function ls($curpath) {
$dir = dir($curpath);
while ($file = $dir->read()) {
if($file != “." && $file != “..") {
if (is_dir($curpath.$file)) {
$stat = stat($curpath.$file);
if ($stat[4] == 999) {
// Once all of the dhapache files are deleted, uncomment the following line and refresh to delete the directories. Non-empty dirs will not be deleted, so any files not owned by “dhapache" may need to be manually deleted via FTP in order to delete the dhapache-owned directory.
// rmdir($curpath.$file);
echo(“$file – $stat[4]" . ‘
‘);
}
ls($curpath.$file."/");
} else {
$stat = stat($curpath.$file);
if ($stat[4] == 999) {
unlink($curpath.$file);
echo(“$file – $stat[4]" . ‘
‘);
}
}
}
}
$dir->close();
return;
}

ls($startpath);
?>