Jump to content

Directory System


proctk

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.