|
Posted by petersprc on 10/11/06 14:16
To expand a wildcard pattern, try the glob function. unlink isn't able
to handle wildcards. For instance:
$zips = glob("$theDir/*.zip");
if ($zips === false) {
die("glob failed.");
}
foreach ($zips as $zip) {
unlink($zip) or die("unlink failed.");
}
comp.lang.php wrote:
> Once again, I thought my class method deleteZip() would do the trick,
> but it never deletes any .zip* file found in a directory:
>
> [PHP]
> /**
> * Delete any latent ZIP files found in this album. This method is to
> be inherited by all listing classes to allow for
> * list-wide deletion of latent server-created ZIP files for security
> purposes
> *
> * @access private
> * @see actual_path
> * @see is_class
> */
> function &deleteZip() { // STATIC VOID METHOD
> global $section, ${$section . 'LocationPath'}, $projectFullName;
> $album = $_REQUEST['album'];
> $locationPath = ($album) ? "${$section . 'LocationPath'}/$album" :
> ${$section . 'LocationPath'};
> if (@!is_class($this->dbAP, 'DBActionPerformer')) $this->dbAP =& new
> DBActionPerformer(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
> if (!$_ENV['windir']) { // UNIX VERSION
> $statMsg = exec("stat \"" . actual_path($locationPath) . "/*.zip*\"
> 2>&1"); // USE UNIX CHECK 'stat' FOR LOCATING ANY ZIP FILES, DO
> DELETION IF AT LEAST 1 FOUND
> } else { // WINDOWS VERSION
> list($lsKommand, $lsRedirect) =
> @array_values($this->dbAP->getKommandOSArray('ls'));
> $statMsg = exec("$lsKommand \"" . actual_path($locationPath) .
> "/*.zip*\" $lsRedirect");
> }
> if (@!unlink(actual_path($locationPath) . '/*.zip*') &&
> !preg_match('/no such file/i', $statMsg)) { // WEB SERVER CANNOT
> DELETE ZIP FILES
> list($removeKommand, $removeRedirect) =
> @array_values($this->dbAP->getKommandOSArray('rmdir-force'));
> $msg = exec("$removeKommand \"" . actual_path($locationPath) .
> "/*.zip*\" $removeRedirect"); // ALLOW FOR THE SERVER ITSELF TO
> DELETE THEM
> if (preg_match('/^rm:/i', $msg) || ($_ENV['windir'] && $msg))
> die("$projectFullName shut down due to security issue with
> potentially damaging ZIP file in \"$locationPath\", please contact
> administrator<p>Error: $msg");
> }
> }
>
> [/PHP]
>
> This is what happens:
>
> [quote]
> statMsg = stat: cannot stat `/www/html/tools/app/images/doom/*.zip*':
> No such file or directory
> [/quote]
>
> um, sorry but there *IS* at lease 1 zip file in
> /www/html/tools/app/images/doom called images_of_doom.zip that is
> auto-generated and does exist when I do "ls -l" via command line,
> permissions of 0644.
>
> How do I delete it and any other ZIP file, plain and simple, I thought
> this would work and it doesn't, please help
>
> thanx
> phil
[Back to original message]
|