Skip to content

Instantly share code, notes, and snippets.

@catalint
Created August 14, 2013 13:09
Show Gist options
  • Save catalint/6230882 to your computer and use it in GitHub Desktop.
Save catalint/6230882 to your computer and use it in GitHub Desktop.
nip framework - Nip_File_System/emptyDir bug
public function emptyDir($dir) {
$this->denyDelete();
$dir = rtrim($dir, "/");
$files = scandir($dir);
array_shift($files);
array_shift($files);
foreach ($files as $file) {
$file = $dir . '/' . $file;
if (is_dir($file)) {
$this->removeDir($file);
} else {
unlink($file);
}
}
}
@catalint
Copy link
Author

Folderele "." si ".." nu sunt intotdeauna primele (ex. fisier care incepe cu "-")

asadar

array_shift($files);
array_shift($files);

prone to bug , sa se duca in directorul superior si sa stearga fisiere care nu vroiam sa stearga

varianta ok:

foreach ($files as $file) {
            if($file=='.' || $file=='..')continue;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment