Scripts

Directory uitlezen

Dit script gebruikt enkele afbeeldingen. Die zijn op de volgende adressen te downloaden: http://users.telenet.be/source/img.rar PHPhulp mirror Dit script lees een directory uit als apache dat doet, wanneer je het voorbeeld zal zien zal je denken dat er gewoon geen index.php bestand is maar dat is er wel. Je mag een paar dingen instellen die in het begin staan van het script: Dit bepaald welke directory hij uitleest. Als hij de directory moet uitlezen waarin het bestand staad, moet je het gewoon leeglaten. Met dit kan je kiezen welke extensies hij mag tonen voorbeeld: ik wil geen html en php bestanden zien: Als je geen directories wil zien type je als extensie dir Als je wilt dat hij bepaalde bestanden (of directories) niet toont geef je die hier op: Als je nog vragen hebt stel ze gerust maar Update Kheb alle icoontjes die we niet nodig hadden uit de zip gehaald --- Ik heb het script wat duidelijker gemaakt, een stuk of 50 icoontjes toegevoegd. Maar ik ga geen switch gebruiken in plaats van if(). want het komt op hetzelfde neer en veel korter is het niet... --- Hier kan je de icons downloaden als geen apache hebt: http://users.telenet.be/source/img.rar

directory-uitlezen
<?php
$dir='';//Leeg laten voor de deze directory te scannen
$n_ext=array('');// extensies voorbeeld: array('html','php') voor directories schrijf je als extensie dir
$n_file=array('.htaccess', '.htpasswd');// bestanden of mappen die niet mogen getoont worden
//------------------------------------
//iconnen die gebruikt worden
//------------------------------------
//Compressed
$icons['zip']='compressed';
$icons['rar']='compressed';
$icons['z']='compressed';
$icons['tgz']='compressed';
$icons['gz']='compressed';
$icons['tar']='compressed';

//Binary

$icons['bin']='binary';
$icons['exe']='binary';
$icons['hqx']='binhex';

//andere bestanden (volgens apache bestaad dat ook :D)

$icons['wrl']='world2';
$icons['vrml']='world2';
$icons['vrm']='world2';
$icons['iv']='world2';
$icons['ps']='a';
$icons['ai']='a';
$icons['eps']='a';
$icons['c']='c';
$icons['pl']='p';
$icons['py']='p';
$icons['f']='for';
$icons['dvi']='dvi';
$icons['uu']='uuencoded';
$icons['core']='bomb';


//Sites

$icons['html']='layout';
$icons['shtml']='layout';
$icons['htm']='layout';
$icons['pdf']='layout';

//Text

$icons['txt']='text';

//Scripts

$icons['php']='script';
$icons['conf']='script';
$icons['sh']='script';
$icons['shar']='script';
$icons['csh']='script';
$icons['ksh']='script';
$icons['tcl']='script';

//Directories en vorige directory

$icons['..']='back';
$icons['']='folder';

//Zelf toegevoegde icononen die ook in apache zitten maar niet gebruikt worden

//foto's

$icons['gif']='image2';
$icons['jpg']='image2';
$icons['png']='image2';
$icons['bmp']='image2';
$icons['pntg']='image2';
$icons['pnt']='image2';
$icons['mac']='image2';
$icons['pict']='image2';
$icons['pic']='image2';
$icons['pct']='image2';
$icons['qtif']='image2';
$icons['qti']='image2';
$icons['sgi']='image2';
$icons['rgb']='image2';
$icons['targa']='image2';
$icons['tga']='image2';
$icons['tif']='image2';
$icons['tiff']='image2';
$icons['psd']='image2';

//Films

$icons['mpg']='movie';
$icons['mpeg']='movie';
$icons['mov']='movie';
$icons['qt']='movie';
$icons['wmv']='movie';
$icons['avi']='movie';
$icons['flc']='movie';
$icons['fli']='movie';
$icons['m1s']='movie';
$icons['m1v']='movie';
$icons['m1a']='movie';
$icons['m75']='movie';
$icons['m15']='movie';
$icons['mp2']='movie';
$icons['mpm']='movie';
$icons['mpv']='movie';
$icons['mpa']='movie';
$icons['3gp']='movie';
$icons['3gpp']='movie';
$icons['3g2']='movie';
$icons['3gp2']='movie';
$icons['mp4']='movie';
$icons['mpg4']='movie';
$icons['sdv']='movie';
$icons['amc']='movie';
$icons['m4v']='movie';
$icons['swf']='movie';
$icons['dv']='movie';
$icons['dif']='movie';


//Geluids bestanden

$icons['wav']='sound1';
$icons['bwf']='sound1';
$icons['midi']='sound1';

//Muziek

$icons['mp3']='sound2';
$icons['wma']='sound2';
$icons['au']='sound2';
$icons['aiff']='sound2';
$icons['au']='sound2';
$icons['snd']='sound2';
$icons['ulw']='sound2';
$icons['qcp']='sound2';
$icons['sd2']='sound2';
$icons['amr']='sound2';
$icons['gsm']='sound2';
$icons['aiff']='sound2';
$icons['m4a']='sound2';
$icons['m4p']='sound2';
$icons['m4b']='sound2';
$icons['swa']='sound2';
$icons['m4b']='sound2';

//------------------------------------
//Functie voor te kijken of het bestand toegelaten is
//------------------------------------
function check_allow($file){
	global $n_ext, $n_file, $icons;
	
	for($a=0;$a<count($n_ext);$a++){
		$ext=explode('.',$file);
		$ext_check=count($ext);
		$ext=$ext[count($ext)-1];
		if(is_file($file)){
			$img=$icons[strtolower($ext)];
	    }
	    else{
	    	$img='';
		}
		if($img==''){
			$ext='dir';
		}
		if($ext==$n_ext[$a]){
			$allow=1;
		}
	}
	
	for($a=0;$a<count($n_file);$a++){
		if($file==$n_file[$a]){
			$allow=1;
		}
	}
	if(isset($allow)){
		return FALSE;
	}
	else{
		return TRUE;
	}
}
//------------------------------------
//Begin van de pagina
//------------------------------------
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of '.$dir.'/</title>
 </head>
 <body>';
echo '<h1>Index of '.$dir.'/</h1>'."\n".'<pre>';
//------------------------------------
//Sorteer volgorder en dan opslaan in $sort
//------------------------------------
if(isset($_GET['C'])){
	$type=explode(';O=',$_GET['C']);
	$sort_by=$type[0];
	$sort_way=$type[1];
	if(($sort_by=='N' || $sort_by=='M' || $sort_by=='S' || $sort_by=='D') && ($sort_way=='A' || $sort_way=='D')){
		if($sort_by=='N'){
			if($sort_way=='A'){
				$n='D';
				$m='A';
				$s='A';
				$d='A';
			}
			else{
				$n='A';
				$m='A';
				$s='A';
				$d='A';	
			}
			$sort=1;
		}
		elseif($sort_by=='M'){
			if($sort_way=='A'){
				$n='A';
				$m='D';
				$s='A';
				$d='A';
			}
			else{
				$n='A';
				$m='A';
				$s='A';
				$d='A';	
			}
			$sort=2;
		}
		elseif($sort_by=='S'){
			if($sort_way=='A'){
				$n='A';
				$m='A';
				$s='D';
				$d='A';
			}
			else{
				$n='A';
				$m='A';
				$s='A';
				$d='A';	
			}
			$sort=3;
		}
		elseif($sort_by=='D'){
			if($sort_way=='A'){
				$n='A';
				$m='A';
				$s='A';
				$d='D';
			}
			else{
				$n='A';
				$m='A';
				$s='A';
				$d='A';	
			}
		}
	}
	else{
		$n='D';
		$m='A';
		$s='A';
		$d='A';
	}
}
else{
	$n='D';
	$m='A';
	$s='A';
	$d='A';
}
echo '<img src="/icons/blank.gif" alt="Icon "> <a href="?C=N;O='.$n.'">Name</a>                    ';
echo '<a href="?C=M;O='.$m.'">Last modified</a>      ';
echo '<a href="?C=S;O='.$s.'">Size</a>  ';
echo '<a href="?C=D;O='.$d.'">Description</a><hr>';
//------------------------------------
//Directory openen en alles in een array zetten zodat we het nog kunnen sorteren later
//En controle of het bestand is toegelaten
//------------------------------------
if($dir==''){
	$open_dir='.';
}
else{
	$open_dir=$dir;
}
$handle=opendir($open_dir); 
$a=0;
$test_iri=str_replace(basename($_SERVER['PHP_SELF']),'',$_SERVER['REQUEST_URI']);
$test_iri=explode('?',$test_iri);
$test_iri=$test_iri[0];
while (false!==($file = readdir($handle))) { 
	if($file!='.'){
		if($file!='..'){
			$ext=explode('.',$file);
			$ext_check=count($ext);
			$ext=$ext[count($ext)-1];
			if(is_file($file)){
				$img=$icons[strtolower($ext)];
			}
			else{
				$img='';
			}
			if($img=='' && $ext!='' && $ext_check>=2){
				$img='unknown';
			}
			elseif($img==''){
				$img=$icons[''];
				$file=$file.'/';
				$ext='';
			}
		}
		else{
			$img=$icons['..'];
			$ext='dir';
		}
		if($test_iri=='/'){
			$test=($file!='..');
		}
		else{
			$test=TRUE;
		}
		if($test && check_allow($file)){
			$files_file[$a]=$file;
			$files_ext[$a]=$ext;
			$files_time[$a]=filemtime($file);
			if($files_ext[$a]==''){
				$size='  -';
			}
			else{
				$size=round(filesize($files_file[$a])/1024,1).'K';
			}
			$files_size[$a]=$size;
			$a++;
		}
	}
}

closedir($handle); 
//------------------------------------
//Als de lijst moet gesorteert worden
//------------------------------------
if($sort==1){
	if($sort_way=='A'){
		array_multisort($files_file, SORT_ASC, $files_ext, SORT_ASC, $files_time, SORT_ASC, $files_size, SORT_ASC);
	}
	else{
		array_multisort($files_file, SORT_DESC, $files_ext, SORT_DESC, $files_time, SORT_DESC, $files_size, SORT_DESC);
	}
}
elseif($sort==2){
	if($sort_way=='A'){
		array_multisort($files_time, SORT_ASC, $files_ext, SORT_ASC, $files_file, SORT_ASC, $files_size, SORT_ASC);
	}
	else{
		array_multisort($files_time, SORT_DESC, $files_ext, SORT_DESC, $files_file, SORT_DESC, $files_size, SORT_DESC);
	}
}
elseif($sort==3){
	if($sort_way=='A'){
		array_multisort($files_size, SORT_ASC, $files_ext, SORT_ASC, $files_file, SORT_ASC, $files_time, SORT_ASC);
	}
	else{
		array_multisort($files_size, SORT_DESC, $files_ext, SORT_DESC, $files_file, SORT_DESC, $files_time, SORT_DESC);
	}
}
//------------------------------------
//Alles echo'en
//------------------------------------
for($b=0;$b<$a;$b++){
	if($files_ext[$b]==''){
		$alt='[DIR]';
	}
	else{
		$alt='['.strtoupper($files_ext[$b]).']';
	}
	echo '<img src="/icons/'.$icons[$files_ext[$b]].'.gif" width="20" height="22" alt="'.$alt.'"> ';
	echo '<a href="'.$files_file[$b].'">'.$files_file[$b].'</a>';
	$spaces=24-strlen($files_file[$b]);
	for($c=0;$c<$spaces;$c++){
		echo ' ';
	}
	echo date('d\-M\-Y H\:i',$files_time[$b]);
	echo '  '.$files_size[$b]."\n";
}
//------------------------------------
//Einde van de pagina
//------------------------------------
echo '<hr></pre><address>'.$_SERVER['SERVER_SIGNATURE'].'</address>';
?></body></html>

Reacties

0
Nog geen reacties.