Location: PHPKode > scripts > Bohemian Image Gallery > w3easyAdmin/w3eA_functions.php
<?php
/*
function path_to_folder ($path_to_folder)
function array_einlesen ($path, $datei)
function read ($path, $datei)
function write ($path, $datei, $text)
function ordner_leer_oder_voll($folder, $select)
function show_dir ($folder, $select, $tag)
function showPOST ()
*/
#############################################################################
/*
function path_to_folder ($path_to_folder)
{
	$path_to_folder = $folder_base;
	$path_to_folder = explode("/",$path_to_folder); // value is taken from config.php
	$path_to_folder  = array_reverse($path_to_folder);
	if (isset($path_to_folder[1])) {$folder_selected = $path_to_folder[1]; $slash_p0 = "/";}
		else {$folder_selected = ""; $slash_p0 = "./";}
	if (isset($path_to_folder[2])){$p1_fold_selected = $path_to_folder[2]; $slash_p1 = "/";}
		else {$p1_fold_selected = ""; $slash_p1 = "";}
	if (isset($path_to_folder[3])){$p2_fold_selected = $path_to_folder[3]; $slash_p2 = "/";}
		else {$p2_fold_selected = ""; $slash_p2 = "";}
	if (isset($path_to_folder[4])){$p3_fold_selected = $path_to_folder[4]; $slash_p3 = "/";}
		else {$p3_fold_selected = ""; $slash_p3 = "";}
	if (isset($path_to_folder[5])){$p4_fold_selected = $path_to_folder[5]; $slash_p4 = "/";}
		else {$p4_fold_selected = ""; $slash_p4 = "";}
	if (isset($path_to_folder[6])){$p5_fold_selected = $path_to_folder[6]; $slash_p5 = "/";}
		else {$p5_fold_selected = ""; $slash_p5 = "";}
		
	if (isset($path_to_folder[7])){$p6_fold_selected = $path_to_folder[7]; $slash_p6 = "/";}
		else {$p6_fold_selected = ""; $slash_p6 = "";}
	if (isset($path_to_folder[8])){$p7_fold_selected = $path_to_folder[8]; $slash_p7 = "/";}
		else {$p7_fold_selected = ""; $slash_p7 = "";}
		
	$path_to_folder  = $p7_fold_selected.$slash_p7.$p6_fold_selected.$slash_p6;
	$path_to_folder .= $p5_fold_selected.$slash_p5.$p4_fold_selected.$slash_p4.$p3_fold_selected.$slash_p3;
	$path_to_folder .= $p2_fold_selected.$slash_p2.$p1_fold_selected.$slash_p1.$folder_selected.$slash_p0;
	$folder_status		= "&nbsp; Selected: ".$path_to_folder;
}
*/
#############################################################################

function array_einlesen ($path, $datei)
// .csv file zeilenweise in array einlesen
{
	$handle = fopen($path.$datei, 'r'); // Einlesen der datei als array
	$i = 0;
	while ($data = fgetcsv($handle, 1000))
	{
		$array[$i] = $data;
		$i ++;
	}
	fclose($handle);
	return $array;
}
// var_dump (array_einlesen ($path, $datei)); echo "<br>\n"; // Funktionstest

#############################################################################

function read ($path, $datei)
{
	$text = "";
	if (is_file($path.$datei)){
		$speicher = file($path.$datei);
		$anzahl = count($speicher);
		$i = 0;
		while ($i <= $anzahl -1)
		{
			$text .= $speicher[$i];
			$i ++;
		}	
	}
	else {
		$text = "File does not exist";
	}
	return $text;
}

#############################################################################

function write ($path, $datei, $text)
{
	$datei = fopen($path.$datei, "w");
	flock($datei,LOCK_EX);
	fputs($datei,$text);
	flock($datei,LOCK_UN);
	fclose($datei);
}

#############################################################################

function ordner_leer_oder_voll($folder, $select) // not verified
{
	$handle = opendir ($folder);
	// Prüfen, ob ein Verzeichnis Ordner bzw. Dateien enthält
	$i = 0;
	while ($fof = readdir ($handle))
	{
		if ($select == "folder"){
			if (!is_file($folder."/".$fof) && $fof != "." && $fof != ".."){
				$i++;
				if ($i == 1){break;}
			}
		}
		else if ($select == "files"){
			if (!is_dir($folder."/".$fof)){
				$i++;
				if ($i == 1){break;}
			}
		}
		else if ($select == "fof"){
			if ($fof != "." && $fof != ".."){
				$i++;
				if ($i == 1){break;}
			}
		}
	}
	closedir($handle);
	if ($i == 0) {$result = "empty (no ".$select.")";}
	if ($i == 1) {$result = "there are ".$select;}
	return $result;
}

#############################################################################

function show_dir ($folder, $select, $tag)
{
	if (file_exists($folder)){
		if (count(scandir($folder)) > 0){
			$handle = opendir($folder);			
			while ($fof = readdir($handle)){
				if ($select == "files"){
					if ($fof != '.' && $fof != '..' && is_file($folder."/".$fof) == true){ // kein Verzeichnis!
	//					$array[] = "<a target='_blank' href='".$folder."/".$fof."'>".$fof."</a><br>\n";
	//					$array[] = "<".$tag.">".$folder."/".$fof."</".$tag.">\n";
						$array[] = "<".$tag.">".$fof."</".$tag.">\n";
					}
				}
				if ($select == "folder"){
//					if (ordner_leer_oder_voll($folder,$select) != "leer"){				
						if ($fof != '.' && $fof != '..' && is_dir($folder."/".$fof) == true){ // keine Datei!
		//					$array[] = "<a target='_blank' href='".$folder."/".$fof."'>".$fof."</a><br>\n";
		//					$array[] = "<".$tag.">".$folder."/".$fof."</".$tag.">\n";
							$array[] = "<".$tag.">".$fof."</".$tag.">\n";
						}
//					}
//					else if (ordner_leer_oder_voll($folder,$select) == "leer"){
//						$array[] = "no file resp. folder";
//					}
				}				
				if ($select == "files_folder"){
					if ($fof != '.' && $fof != '..'){
	//					$array[] = "<a target='_blank' href='".$folder."/".$fof."'>".$fof."</a><br>\n";
	//					$array[] = "<".$tag.">".$folder."/".$fof."</".$tag.">\n";
						if (is_dir($folder."/".$fof) == true){
							$array[] = "<".$tag.">".$fof."</".$tag.">\n";
						}
						if (is_file ($folder."/".$fof) == true){
							$array[] = "<".$tag.">".$fof."</".$tag.">\n";
						}
//						$array[] = "<".$tag.">".$fof."</".$tag.">\n";
					}
				}
				if ($select == "fof"){
					if ($fof != '.' && $fof != '..'){
	//					$array[] = "<a target='_blank' href='".$folder."/".$fof."'>".$fof."</a><br>\n";
	//					$array[] = "<".$tag.">".$folder."/".$fof."</".$tag.">\n";
						if (is_dir($folder."/".$fof) == true){
							$array[] = "<".$tag.">".$fof."</".$tag.">\n";
						}
						if (is_file ($folder."/".$fof) == true){
							$array[] = "<".$tag.">".$fof."</".$tag.">\n";
						}
//						$array[] = "<".$tag.">".$fof."</".$tag.">\n";
					}
				}
			}
			closedir ($handle);
		}
		else{
			$array[] = "no file resp. folder";
		}
	}	
	$anz = count($array);
	if ($anz > 1){sort($array);}
	$fof_list = "";
	$i = 0;
	while ($i<$anz){$fof_list .= $array[$i]; $i++;}
	return $fof_list;
}

#############################################################################

function showPOST ()
{
	if ($_POST != ""){
		$anz = count($_POST);
		$post = "";
		$j = 1;
		foreach ($_POST as $index => $wert)
		{
			if ($index == "text"){$wert = "TEXT";}
	//		$post .= $j." &nbsp; ".$index." : ".$wert."<br>\n";
			$post .= sprintf("%03d",$j)." &nbsp; ".$index.": ".$wert."<br>\n";
			$j++;
		}
	}
	// else {$post = "";}
	else {$post = "POST array is empty";}
	return $post;
}

#############################################################################

?>
Return current item: Bohemian Image Gallery