Because of the nature of what I am trying to do, I am not at liberty to do this:
$dirID = @opendir($myDirectoryPath);
if ($dirID) {
while (($fyl = @readdir($dirID)) !== false) {
if (is_file("$myDirectoryPath/$fyl") && preg_match('/^[a-zA-Z0-9\_]+/i', $fyl))
@unlink("$myDirectoryPath/$fyl");
}
}
There could be literally hundreds to thousands of image files, anywhere between 100K and 10mb each, try looping THAT!
Instead I want to do an OS-based deletion whereby it does it at once:
if (!$cdKommand) list($cdKommand, $cdRedirect) = @array_values($this->getKommandOSArray('cd'));
list($removeKommand, $removeRedirect) = @array_values($this->getKommandOSArray('rmdir'));
if ($this->isSuccessful) $errorMsg = exec("$cdKommand \"$thumbLoc\" $cdRedirect $binder $removeKommand \"". realpath($thumbLoc . '/*.*') . "\" $removeRedirect");
if ($this->isSuccessful && (preg_match('/lstat/i', $errorMsg) || ($_ENV['windir'] && $errorMsg))) {
$this->isSuccessful = false;
$this->setErrorArray(array('action' => "Cannot delete $section thumbnails from \"$thumbLoc\": $errorMsg"));
}
}
What this will do is retrieve the OS-based command to delete all files from a single directory at once. If Windows it should be:
cd "C:/Program Files/Apache Group/Apache2/htdocs/tools/app/images/phil" | del /Q "C:/Program Files/Apache Group/Apache2/htdocs/tools/app/images/phil/."
And if Unix it should be:
cd "/var/www/html/tools/app/images/phil" ; rm -Rf "/var/www/html/tools/app/images/phil/." 2>&1
However, it fails for both OS the exact same way: it deletes everything in ../../ in short, either "C:/Program Files/Apache Group/Apache2/htdocs/tools/app" (if Windows) or "/var/www/html/tools/app" (if Unix).
I am completely not sure why this is happening, when I echo out the directory information I always get the correct directory; when using command-line everything behaves properly.
I can't figure out what to do to resolve this and it's important for my app to be able to delete large amounts of files at once!
Thanx
Phil