Page 1 of 1

Making subdirectories

Posted: Mon Dec 15, 2003 8:35 pm
by kashmirekat
Hi!

I have posted this into phpbuilder.com where they are usually very helpful, but this time I am afraid their suggestions don't work....or it's the coder (which is highly probable :).

I am trying to make subdirectories underneath a new directory I have just created. It makes the directory, only it is located where the script is, not in the directory just created.

I've been informed not to use 'value' and that I need "" around my values for <option>; however, this does not affect the script. I set up a little page at http://www.sacredfalls.net/cpane/testing/ so you can see my problem. I've been working on this for the past 2 days and it is just so frustrating. Grr. Someone, please tell me what I'm doing wrong. I know the code's not perfect, but I started over trying to make it simple so I could see where the problem lie...but alas, that did not work. My code is below.

Code: Select all

<form name="form1" action="<? echo $PHP_SELF ?>" method="post"> 
<? 
if($rename) 
rename($listbox,$value); 

$dirname1 = getcwd(); 

if($chdir) &#123; 
$dirname = ("$dirname1/$listbox");  
$ch = chdir("$dirname1/$listbox"); 
//I'm thinking it has something to do with right here.  When it 
//makes the dir, it doesn't seem to recognize this path.  It just 
//goes back to $dirname1 
$mk = $ch; 
&#125; 
else &#123; $dirname = $dirname1;  
$mk = $dirname1; &#125; 

if($mkdir) &#123; 
mkdir("$mk/$value"); &#125; 
?> 
<select name="listbox" size=4> 
<?  
   $dir = opendir ($dirname); 
   while ($file = readdir ($dir) ) &#123; 
   if (is_dir($dir)) 
   &#123; print "<option name=$file value=$file>$file/<br>"; &#125; 
   else &#123; 
   $filesize = filesize($file); 
   $kbfile = round($filesize/1024,2); 
   print "<option name=$file value=$file>$file ($kbfile kb)<br>"; 
   &#125; 
   &#125; 
   closedir ($dir); 
?> 
</select> 
<input name="value" type="text" value=""> 
<input type="submit" name="rename" value="Rename"> 
<input type="submit" name="chdir" value="Change Dir"> 
<input type="submit" name="mkdir" value="Make Dir"> 
</form>
Thank you for any help.
Happy Holidays.
Christina

Posted: Mon Dec 15, 2003 9:40 pm
by Weirdan
seems like chdir works only for current invocation of the script. You can use session variable to store current path and to chdir there each time the script invoked.

Posted: Tue Dec 16, 2003 6:27 am
by McGruff
Try adding some debug lines so you can track path values as the script progresses:

Code: Select all

<?php

// echo strings

#/* DEB
$location = __FILE__ . ' | line ' . __LINE__ . '<br />';
echo $location;
echo $string1 . '<br />';
#*/

// print arrays or objects:

#/* DEB
$location = __FILE__ . ' | line ' . __LINE__ . '<br />';
echo '<pre>';
echo $location;
print_r($array1);
echo '</pre>';
#*/

?>