|
Posted by Jerry Stuckle on 10/13/06 17:19
comp.lang.php wrote:
> Jerry Stuckle wrote:
>
<snip>
>>$_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.
>
Either way, $_SERVER['DOCUMENT_ROOT'] will point at your web root
directory. Just add your relative path from the root directory - which
the program should know already, anyway. It's just much easier to
reference the web server root directory all the time than to try to
compute the relative path. So you would just use:
$_SERVER['DOCUMENT_ROOT'] . '/blah/foo'
for your directory (yes, Windows understands forward slashes, also -
just the command processor doesn't).
And spaces are not a problem.
Using the PHP directory functions is going to be slower - but it is
transparent to the system. And many shared hosts do not allow PHP
programs to execute shell commands. This will always work, as long as
the files have the appropriate permissions (and if they don't, the shell
command will fail, also).
> 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
>
You don't need actual_path, for one thing. You already have it. And
not knowing what actually is passed in $removeKommand or
$removeRedirect, it's hard to say what happened.
Why not put your command into a string then echo it to see what's
actually in it? And the message that's returned.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|