|
Posted by comp.lang.php on 10/13/06 16:24
Jerry Stuckle wrote:
> comp.lang.php wrote:
> > Tim Roberts wrote:
> >
> >
> >
> > 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?
> >
>
> Why not use the directory functions, such as opendir(), readdir(), etc.?
> They work on all systems. You'll have to test the file extensions,
> but it shouldn't be too bad as the information is cached.
>
>
> >
> >
> > 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.
> >
> >
> $_SERVER['DOCUMENT_ROOT'] always points to the root directory of the
> server, no matter where it is or what platform you're running Apache on
> (it also works with IIS).
[snip]
That doesn't address the fact that your directory, stemming from
$_SERVER['DOCUMENT_ROOT'], could be "/var/www/html/blah/foo" or
"C:\Program Files\Apache Group\Apache\htdocs\blah\foo". Which is why I
will want to delete all of one type of file from a directory, the issue
lies in the fact that I am wanting to use command-line calls to remove
them all at one time (which honestly I thought was a time saver, but
honestly, is that slower or faster than your suggestion of opendir() -
readdir() while loop? I would think the while loop is slower as it has
to loop where a command-line remove command would be faster, but that's
just me), by using the * wildcard I cannot encase the path structure in
double-quotes, but in Windows, my directory from the doc root might
have spaces in it:
c:\Program Files\Apache Group\Apache\htdocs\My Directory\blah\foo
Why anyone would do that would be beyond me, but it is viable to occur
of course.
Also, for some strange reason, whenever I do this, it fails in spite of
the fact that $_SERVER['DOCUMENT_ROOT'] contains the path from the root
to the docroot:
[PHP]
list($removeKommand, $removeRedirect) =
@array_values($dbAP->getKommandOSArray('rmdir')); // GETS EITHER
WINDOWS OR NON-WINDOWS REMOVE COMMANDS AND REDIRECTION
$msg = exec("$removeKommand \"" . actual_path($_SERVER['DOCUMENT_ROOT']
.. '/blah/foo') . "/*.zip*\" $removeRedirect");
[/PHP]
Phil
Navigation:
[Reply to this message]
|