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
https://forums.phpfreaks.com/topic/59832-directory-system/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.