problem with functions and paths

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Can anyone tell me how PHP handles paths?
Do all functions require fully qualified paths or can some use relative  

I'm having a problem with a foreach/glob() at the moment but have others  
to sort out. Is it different for windows and linux?  

On Windows:
if I do (using apache2)

$path = 'c:\server\mydomain';

foreach (glob($path . "*", GLOB_ONLYDIR) as $folder) {

It all works fine but if I set $path as:
$path = '../../../mydomain/';

I get an:
Warning: Invalid argument supplied for foreach()  
I've tried reversing and escaping the slashes with no luck.

Is there a fixed rule for relative & fully qualified paths?


Re: problem with functions and paths

harvey wrote:

Quoted text here. Click to load it


I never used relative paths in glob.
Why not make a full path first of your relative path?

And also: Why not check first if your target directory is actually a  
directory before feeding it to glob? Use function is_dir().

Erwin Moller

Re: problem with functions and paths

On Tue, 19 Jun 2007 07:55:10 GMT, harvey wrote...
Quoted text here. Click to load it

If you need back slashes in your full path, then you'd probably need them in
your relative path. Maybe this instead...


..but It looks like you might be trying to go back too far. Since your system's
root is at "c:\" it looks like you only need to go back two directories instead
of three. You probably be better off using the complete path instead.

Basic Accounts $5.95 / month or $39.95 / 12 months

Site Timeline