note 102565 deleted from function.unlink by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 12:16:14 +0000 |
| Subject: | note 102565 deleted from function.unlink by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197121@lists.php.net to get a copy of this message | ||
Note Submitter: webmaster at sebastiangrinke dot info
----
If you have a problem with unwriteable files test this ;)
Its a bit longer but it works really fine for me :)
<?php
public function delete_folder($tmp_path){
if(!is_writeable($tmp_path) && is_dir($tmp_path)){chmod($tmp_path,0777);}
$handle = opendir($tmp_path);
while($tmp=readdir($handle)){
if($tmp!='..' && $tmp!='.' && $tmp!=''){
if(is_writeable($tmp_path.DS.$tmp) && is_file($tmp_path.DS.$tmp)){
unlink($tmp_path.DS.$tmp);
}elseif(!is_writeable($tmp_path.DS.$tmp) && is_file($tmp_path.DS.$tmp)){
chmod($tmp_path.DS.$tmp,0666);
unlink($tmp_path.DS.$tmp);
}
if(is_writeable($tmp_path.DS.$tmp) && is_dir($tmp_path.DS.$tmp)){
delete_folder($tmp_path.DS.$tmp);
}elseif(!is_writeable($tmp_path.DS.$tmp) && is_dir($tmp_path.DS.$tmp)){
chmod($tmp_path.DS.$tmp,0777);
delete_folder($tmp_path.DS.$tmp);
}
}
}
closedir($handle);
rmdir($tmp_path);
if(!is_dir($tmp_path)){return true;}
else{return false;}
}
?>