creating a path appending folders... how to add them???

A

Anonymous

Guest
I am trying to create a path by passing the folder name as a var.
for example:
Code:
<?php
$myfolder = "graphics";
if ($handle = opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
    echo "Files:\n";
?><br><?php
    while (false !== ($file = readdir($handle))) {
	$mydir = dirname($file);
	$mydir = $mydir+"/" +$graphics; <----HERE IS the problem?
	$file = basename ($file,".htm");
                echo "$file\n"; 
	echo "$mydir\n";
?>

mydir is now the root directory, but i want to give it a folder name (that exists of course) and make it ouput that full path
 
I'm quite sure PHP doesn't use +'s. Try replacing the +'s with .'s (periods)

Code:
$mydir = $mydir."/".$graphics; <----HERE is the solution /code]
 
Xerpher said:
I'm quite sure PHP doesn't use +'s. Try replacing the +'s with .'s (periods)

Code:
$mydir = $mydir."/".$graphics; <----HERE is the solution /code][/quote]

THANKS!!! That did it. (back to the drawing board!)  :D  :D
 
imroue said:
I am trying to create a path by passing the folder name as a var.
for example:
Code:
<?php
$myfolder = "graphics";
if ($handle = opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
    echo "Files:\n";
?><br><?php
    while (false !== ($file = readdir($handle))) {
	$mydir = dirname($file);
	$mydir = $mydir+"/" +$graphics; <----HERE IS the problem?
	$file = basename ($file,".htm");
                echo "$file\n"; 
	echo "$mydir\n";
?>

mydir is now the root directory, but i want to give it a folder name (that exists of course) and make it ouput that full path
I would amend your code slightly, see if you can spot the difference:
Code:
<?php
$myfolder = "graphics";
if ($handle = opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
    echo "Files:<br>\n";
    while ($file = readdir($handle)) {
	$mydir = dirname($file);
	$mydir = $mydir."/".$graphics;
	$file = basename($file.".htm");
                echo "$file\n"; 
	echo "$mydir\n";
    }
}
?>
 
mydir is now the root directory, but i want to give it a folder name (that exists of course) and make it ouput that full path[/quote]
I would amend your code slightly, see if you can spot the difference:
Code:
<?php
$myfolder = "graphics";
if ($handle = opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
    echo "Files:<br>\n";
    while ($file = readdir($handle)) {
	$mydir = dirname($file);
	$mydir = $mydir."/".$graphics;
	$file = basename($file.".htm");
                echo "$file\n"; 
	echo "$mydir\n";
    }
}
?>

Thanks, that works too, but I just realized, I 've been going around in circles...the var $file contains files in the ROOOT directory...I was trying to get the root directory so I can append the graphics directory to it..and THEN read off the file names in $graphics.... NOW that would solve the real issue??? Eventually, I would want to only change the var $graphics and be able to use this page anywhere ....

I tried this.. but of course as a newbie..it didn't work:
opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT']."/".$graphics))

Any ideas?
 
Well in my experience, putting array values in a function never seems to work. It could just be me, I truly dont know, but I know that on my server I would have to put this...

Code:
$rootdir = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
...BEFORE your opendir and change it to this...

Code:
opendir($rootdir."/".$graphics))
I hope Jay reads this and tells me if its some kind of glitch on my server that I have to do this or if its normal.
 
Must be a glitch, it's definately not normal! If a function requires a parameter and that parameter is an array key, you can reference the key directly to serve as the parameter

opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT']."/".$graphics) should work!
 
imroue said:
mydir is now the root directory, but i want to give it a folder name (that exists of course) and make it ouput that full path
I would amend your code slightly, see if you can spot the difference:
Code:
<?php
$myfolder = "graphics";
if ($handle = opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT'])) {
    echo "Files:<br>\n";
    while ($file = readdir($handle)) {
	$mydir = dirname($file);
	$mydir = $mydir."/".$graphics;
	$file = basename($file.".htm");
                echo "$file\n"; 
	echo "$mydir\n";
    }
}
?>

Thanks, that works too, but I just realized, I 've been going around in circles...the var $file contains files in the ROOOT directory...I was trying to get the root directory so I can append the graphics directory to it..and THEN read off the file names in $graphics.... NOW that would solve the real issue??? Eventually, I would want to only change the var $graphics and be able to use this page anywhere ....

I tried this.. but of course as a newbie..it didn't work:
opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT']."/".$graphics))

Any ideas?[/quote]
IF you want to read the the graphics directory just do this
Code:
<?php
$myfolder = "graphics";
if ($handle = opendir($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$myfolder)) {
    echo "Files:<br>\n";
    while ($file = readdir($handle)) {
                print "$file<br>\n";
    }
}
?>
 
Back
Top