Bir Klasörün İçindeki Tüm Dosya ve Klasörleri Görüntülemek

<?php
class DerinDizin{
  var $dizin;
  var $dosyalar;
  function DerinDizin(){
    $this->dizin = '';
    $this->dosyalar = array();
    $this->dizinelemanlar = new elemanlar();
  }
  function dizinAyarla( $dizin ){
    $this->dizin = $dizin;
    $this->dosyalar = array();
    $this->dizinelemanlar->sifir();
    $this->dizinelemanlar->push( $this->dizin );
  }
  function yukle(){
    while( $this->mevcutDizin = $this->dizinelemanlar->pop() ){
      $this->mevcutDizindenYukle();
    }
  }
  function mevcutDizindenYukle(){
    if ( $kol = @opendir( $this->mevcutDizin ) ){
      while ( false !== ( $dosya = readdir( $kol ) ) ){
        if ( $dosya == "." || $dosya == ".." ) continue;
        $dosyaYolu = $this->mevcutDizin . '/' . $dosya;
        $dosyatipi = filetype( $dosyaYolu );
        if ( $dosyatipi == 'dir' ){
          $this->dizinelemanlar->push($dosyaYolu);
          continue;
        }
        $this->dosyalar[]=$dosyaYolu;
      }
      closedir($kol);
    }
    else{
      echo 'Hata : Dizin Açılamıyor "'.$this->mevcutDizin.'"';
    }
  }
}
class elemanlar{
  var $elemanlar;
  function elemanlar(){
    $this->sifir();
  }
  function push( $eleman ){
    array_push( $this->elemanlar, $eleman );
  }
  function pop(){
    return array_pop( $this->elemanlar );
  }
  function sifir(){
    $this->elemanlar = array();
  }
}
$dizinAdi = '..';
$dizin = new DerinDizin();
$dizin->dizinAyarla($dizinAdi);
$dizin->yukle();
foreach( $dizin->dosyalar as $n => $kolYolu ){
	echo ($n+1)." ".$kolYolu."<br>";
}
?>

Çıktısı

1 ../localweb/index.php
2 ../localweb/test/2.txt
3 ../localweb/test/a/b.php
4 ../databases/tr.txt
5 ../conf/asd.txt
6 ../conf/test.conf
7 ../conf/test2.conf

 

URI Üzerindeki GET Sorgu Dizesi Parametrelerini İşlemek

<?php
class adres {
	var $adres;
	var $site;
	var $deger;
	var $gecici;
	function adres($def="") {
		$this->adres = $def;
		preg_match('/^(.*\?)(.*)$/', $this->adres, $sonuc);
		$this->site = $sonuc[1];
		unset($this->deger);
		$sekme = (explode("&", $sonuc[2]));
		foreach($sekme as $s) {
			$gecici = explode("=", $s);
			$this->deger[$gecici[0]] = $gecici[1];
		}
	}
	function degerEkle($veri, $sal) {
		$this->deger[$veri] = $sal;
	}
	function degerKaldir($veri) {
		unset($this->deger[$veri]);
	}
	function degerGoster($veri) {
		return $this->deger[$veri];
	}
	function yeniAdres() {
		foreach($this->deger as $k=>$s) {
			$this->gecici[] .= $k."=".htmlentities(urlencode($s));
		}
		return $this->site.implode("&",$this->gecici);
	}
}
$x = new adres("http://localhost/index.php?veri1=01&veri2=02");
echo $x->degerGoster("veri1");
echo $x->degerEkle("veri3", "03");
echo $x->degerKaldir("veri2");
echo "<br>";
echo $x->yeniAdres();
?>

Çıktısı

01
http://localhost/index.php?veri1=01&veri3=03