The Little Guy Posted May 29, 2007 Share Posted May 29, 2007 anyone know of a way to echo out all the files and directories in the root of the site, and for each subdirectory, and subdirectories of the subdirectory, and so on? Quote Link to comment https://forums.phpfreaks.com/topic/53370-solved-view-all-files-and-directories/ Share on other sites More sharing options...
Diego17 Posted May 29, 2007 Share Posted May 29, 2007 You can use glob() for that. http://es.php.net/manual/en/function.glob.php Quote Link to comment https://forums.phpfreaks.com/topic/53370-solved-view-all-files-and-directories/#findComment-263734 Share on other sites More sharing options...
The Little Guy Posted May 29, 2007 Author Share Posted May 29, 2007 I don't think that is what I need... I would like to have a code on my site that will make a list of all the files on a users website. Basically, I want the user to come and copy this code to a file on their website, and then the code will be placed in the root folder of their site. When the code runs, I would like it to grab every file textual web file they have created, such as some of these formats: html,htm,php,shtml,asp,dhtml,txt This would also search all subdirectories as well, and save those URL's too. The EXACT URL of each file will then be saved to a txt file that will be saved in their root directory. I would like it to ignore all image files, exe files, and anything that would not contain textual content that can be displayed on the web. anyone know of a way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/53370-solved-view-all-files-and-directories/#findComment-263738 Share on other sites More sharing options...
Diego17 Posted May 29, 2007 Share Posted May 29, 2007 I still think glob() is suitable. You have to write a function that processes one directory and then call itself recursivle for each sub directory. Quote Link to comment https://forums.phpfreaks.com/topic/53370-solved-view-all-files-and-directories/#findComment-263757 Share on other sites More sharing options...
The Little Guy Posted May 29, 2007 Author Share Posted May 29, 2007 <?php function kids($dir, $allowed_extensions) { if ($handle = opendir($dir)) { $output = array(); while (false !== ($item = readdir($handle))) { if (is_dir($dir.'/'.$item) and $item != "." and $item != "..") { $output = array_merge($output, kids($dir.'/'.$item, $allowed_extensions)); } elseif(is_file($dir.'/'.$item) and in_array(preg_replace('/^.*((?<=\.)[^.]+)$/', '$1', $item), $allowed_extensions)) { $output[] = $dir.'/'.$item; } } closedir($handle); return $output; } return false; } print_r(kids('.', array('html','htm','php','shtml','asp','dhtml','txt','cmf','jsp','aspx'))); ?> Quote Link to comment https://forums.phpfreaks.com/topic/53370-solved-view-all-files-and-directories/#findComment-263793 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.