You are here: Re: How do you delete a zip file from a directory? « PHP Programming Language « IT news, forums, messages
Re: How do you delete a zip file from a directory?

Posted by comp.lang.php on 10/12/06 15:40

Tim Roberts wrote:
> "comp.lang.php" <phillip.s.powell@gmail.com> wrote:
>
> >
> >petersprc@gmail.com wrote:
> >> 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.");
> >> }
> >
> >Thanx but how efficient is that? You could be looping through a
> >directory potentially containing thousands of images within my
> >application each time you display a list of them
>
> You shouldn't worry too much about efficiency until you try it. Try doing
> an "ls *.zip" from a command line; the "glob" is going to take roughly the
> same time. The Unix directory APIs are pretty efficient.

Ok cool, however, the requirements for this portable web app is that it
must work in both Unix and Windows environments equally, thus,
obviously can't just do "ls *.zip" but also "dir /w *.zip" as well; how
does "glob" play with Windows?

>
> On the other hand, once you get into "thousands" of images, you might
> consider some clever subdirectories. I have a client that stores PDF and
> JPG files, where the names have the form 'p12345.pdf'. I use mod_rewrite
> to change that to a directory tree p1/23/p12345.pdf. That way, there are
> no more than 100 files per directory.
> -

clever subdirectories are an option inasmuch as PHP requires literal
paths for some of its functionality (I wrote a function "actual_path()"
that takes care of that anyway), however, as this is a portable web
application, I am not sure if that is a viable one, as this application
is designed to "pack up and go" and install anywhere on the planet (or
it should), one simply could not do mod_rewrite on the fly, only an
admin customizing my tool could do that on their end. Good to suggest
though

Phil

PS: I figured something out that might work for Unix/Windows:

[PHP]
if (!$_ENV['windir'] && !$_SERVER['windir']) {
$msg = exec('stat ' . actual_path($locationPath) . '/*.zip* 2>&1');
} else {
list($lsKommand, $lsRedirect) =
@array_values($this->getKommandOSArray('ls-l')); // GETS "ls" COMMAND
APPROPRIATE FOR NON-UNIX SYSTEMS
$msg = exec("$lsKommand \"" . actual_path($locationPath) . "/*.zip*\"
$lsRedirect");
}
[/PHP]
-
> - Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация