proctk Posted July 13, 2007 Share Posted July 13, 2007 Hi I'm trying to create a directory system so that uses can and remove file folders. All members will automatically get start with a file folder in the folder "user_images" which is a sub folder to the root, and a folder equal to their user name. I want to give the person the ability to add delete edit sub folder within their own folder. I have come up with this, which shows supposed to show the folder names in a list box <?php function directoryToArray($directory, $recursive) { $array_items = array(); if ($handle = opendir($directory)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir($directory. "/" . $file)) { if($recursive) { $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive)); } $file = $directory . "/" . $file; $array_items[] = preg_replace("/\/\//si", "/", $file); } else { $file = $directory . "/" . $file; $array_items[] = preg_replace("/\/\//si", "/", $file); } } } closedir($handle); } return $array_items; } $makeDirectory = "user_images/".$user_name.'/'; $files = directoryToArray($makeDirectory, false); echo '<select name="Directories">'; foreach ($files as $file) { $getCategory = explode("/",$file); $category = $getCategory[2]; echo '<option value='.$file.'>' .$category .'</option>'; } echo '</select>'; ?> the problem is this line of code $makeDirectory = "user_images/".$user_name.'/'; [code=php:0] the file that calls this code is saved in a folder "photos" which is a sub folder to the root. IF I change it to $makeDirectory = "../user_images/".$user_name.'/' The select option will show but with incorrect information. If i run the code above from a file saved in the root directory everything works fine. any help would be excellent. Also, if anyone knows of a tutorial that shows how to do what I'm trying to accomplish please share Thank you Quote Link to comment Share on other sites More sharing options...
proctk Posted July 14, 2007 Author Share Posted July 14, 2007 I'm still struggling with with, any ideas how to fix it. Is the a way to reference the a back to the root then go to the folder I want without the ../ Quote Link to comment Share on other sites More sharing options...
proctk Posted July 14, 2007 Author Share Posted July 14, 2007 As noted above I saved the page with this code on it in the root folder and it works fine. The problem has to do with the $makeDirectory = "user_images/".$user_name.'/'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.