支付宝赞助帐号:service@kuitao8.com 

下载地址

php文件树 遍历文件夹的源码下载

Created2013-08-04   Views 2527    Author 懒人程序
php文件树  遍历文件夹的源码下载

function php_file_tree($directory, $return_link, $extensions = array()) {
	// Generates a valid XHTML list of all directories, sub-directories, and files in $directory
	// Remove trailing slash
	if( substr($directory, -1) == "/" ) $directory = substr($directory, 0, strlen($directory) - 1);
	$code .= php_file_tree_dir($directory, $return_link, $extensions);
	return $code;
}




function php_file_tree_dir($directory, $return_link, $extensions = array(), $first_call = true) {
	// Recursive function called by php_file_tree() to list directories/files
	
	// Get and sort directories/files
	if( function_exists("scandir") ) $file = scandir($directory); else $file = php4_scandir($directory);
	natcasesort($file);
	// Make directories first
	$files = $dirs = array();
	foreach($file as $this_file) {
		if( is_dir("$directory/$this_file" ) ) $dirs[] = $this_file; else $files[] = $this_file;
	}
	$file = array_merge($dirs, $files);
	
	// Filter unwanted extensions
	if( !empty($extensions) ) {
		foreach( array_keys($file) as $key ) {
			if( !is_dir("$directory/$file[$key]") ) {
				$ext = substr($file[$key], strrpos($file[$key], ".") + 1); 
				if( !in_array($ext, $extensions) ) unset($file[$key]);
			}
		}
	}
	
	if( count($file) > 2 ) { // Use 2 instead of 0 to account for . and .. "directories"
		$php_file_tree = "" . htmlspecialchars($this_file) . "";
					$php_file_tree .= php_file_tree_dir("$directory/$this_file", $return_link ,$extensions, false);
					$php_file_tree .= "";
				} else {
					// File
					// Get extension (prepend 'ext-' to prevent invalid classes from extensions that begin with numbers)
					$ext = "ext-" . substr($this_file, strrpos($this_file, ".") + 1); 
					$link = str_replace("[link]", "$directory/" . urlencode($this_file), $return_link);
					//$php_file_tree .= "
  • " . htmlspecialchars($this_file) . "
  • "; $php_file_tree .= "
  • " . htmlspecialchars($this_file) . "
  • "; } } } $php_file_tree .= ""; } return $php_file_tree; } // For PHP4 compatibility function php4_scandir($dir) { $dh  = opendir($dir); while( false !== ($filename = readdir($dh)) ) {    $files[] = $filename; } sort($files); return($files); }
    上一篇: jquery html5 codeigniter php视频教程
    下一篇: ecshop视频教程免费下载
    支持键盘 ← →

    邮件订阅

    订阅我们的精彩内容