Uzak Sunucu Dosya İstatiktikleri Sınıfı

<?php
class UzakDosyaKontrol {
	var $hata;
	var $hatano;
	var $hatamesaj;
	var $sunucu;
	var $tarih;
	var $boyut;
	var $tip;
	var $httpcevir = array('Server' => 'sunucu',
		'Last-Modified' => 'tarih',
		'Content-Length' => 'boyut',
		'Content-Type' => 'tip'
		); 
	var $istatistik = array('sunucu' => '',
		'tarih' => '',
		'boyut' => '',
		'tip' => ''
		);
	function UzakDosyaKontrol($sunucu, $file, $port = 80) {
		$file = preg_replace("#^\/|^#i", "/", $file);
		$this->hata = false;
		$fp = fsockopen ($sunucu, $port, $this->hatano, $this->hatamesaj, 30);
		if($fp) {
			fputs ($fp, "HEAD $file HTTP/1.0\r\n");
			fputs ($fp, "Host: $sunucu\r\n" );
			fputs ($fp, "\r\n");
			while(!feof($fp)) {
				$satir = fgets($fp,4096);
				if(preg_match("/^([a-zA-Z\-]+): ([[:ascii:]]+)$/", $satir, $dizi)) {
					if(isset($this->httpcevir[$dizi[1]])) {
						$this->istatistik[$this->httpcevir[$dizi[1]]] = $dizi[2];
					}
				}
			}
		} else {
			$this->hata = true;
		}
	}
	function sunucugetir() {
		return $this->istatistik['sunucu'];
	}
	function tarihgetir() {
		return date("d.m.Y H:i:s",strtotime($this->istatistik['tarih']));
	}
	function boyutgetir() {
		return $this->istatistik['boyut'];
	}
	function tipgetir() {
		return $this->istatistik['tip'];		
	}
	function hatagetir() {
		return $this->hata;
	}
	function hatamesajgetir() {
		return $this->hatamesaj;
	}
	function hatanogetir() {
		return $this->hatano;
	}
	
}
$r = new UzakDosyaKontrol('www.google.com.tr', 'images/branding/googlelogo/2x/googlelogo_color_272x92dp.png');
if($r->hata) {
	echo $r->hatamesajgetir(), '(', $r->hatanogetir(), ')<br>';
}else{
	echo $r->sunucugetir(), 
	'<br>',$r->tarihgetir(), 
	'<br>',$r->boyutgetir(), 
	'bayt<br>',$r->tipgetir(), '<br>';
}
?>

Çıktısı

sffe 
08.12.2016 02:00:57
13504 bayt
image/png

 

Klasör Oluşturarak Dosya Yazma Sınıfı

<?php
class dosyaYazici{
	var $yenimaske= 0;
	var $klasorizin= 0777;
	var $dosyaizin= 0777;
	var $kullanici= "nobody";
	public $hata=null;
	function yeniKlasor($yol,$klasorname){
		if(!file_exists(getcwd().$yol.$klasorname)){
			$oldumask = @umask($this->yenimaske); 
			$b 		  = @mkdir(getcwd().$yol.$klasorname, $this->klasorizin);
						@umask($oldumask);
			if($b==TRUE){
				return TRUE;
			} else {
				$this->hata.="Klasör Oluşturulamadı";
				return FALSE;
			}
		} else return TRUE;
	}
	function yaz($dosya,$icerik){
		if(!empty($dosya) && !empty($icerik)){
			$fp = fopen($dosya,"w");
			$b = fwrite($fp,$icerik);
			fclose($fp);
			@chmod($dosya,$this->dosyaizin);
			@chown($dosya,$this->kullanici);
			if($b != -1){
				return TRUE;
			} else {
				$this->hata.="Dosya Yazılamadı";
				return FALSE;
			}
		} else {
			$this->hata.="Dosya veya İçerik Bulunamadı";
			return FALSE;
		}
	}
	function oku($dosya){
		if(!empty($dosya)){
			$dt = fopen($dosya, "rb");
			$icerik = fread($dt, filesize($dosya));
			fclose($dt);
			echo $icerik;
		} else {
			$this->hata.="Dosya Bulunamadı";
			return FALSE;
		}
	}
}
$fw = new dosyaYazici;
$fw->yeniKlasor("/","klasor");
$fw->yaz(getcwd()."/klasor/file.txt","bubirdenemedir");
$fw->oku(getcwd()."/klasor/file.txt");
echo $fw->hata;
?>

Çıktısı

bubirdenemedir

 

Metni Basitçe Şifreleyerek Dosya Oluşturmak

<?php
header('Content-Type: text/html; charset=utf-8');
mb_internal_encoding('UTF-8');
class Sifre{
	public $bundan=['1','2','3','4','5','6','7','8','9','0',
	'a','b','c','ç','d','e','f','g','ğ','h','ı','i','j','k','l',
	'm','n','o','ö','p','r','s','ş','t','u','ü','v','w','x','y','z',
	'A','B','C','Ç','D','E','F','G','Ğ','H','I','İ','J','K','L',
	'M','N','O','Ö','P','R','S','Ş','T','U','Ü','V','W','X','Y','Z'];
	public $buna=['v','B','i','Y','V','T','K','0','İ','7','n',
	'Ç','x','ğ','b','f','o','Ü','J','z','Ğ','u','9','O','r','W',
	'ş','A','g','ü','4','P','R','5','6','Z','w','s','E','3','y','F',
	'd','I','D','t','ç','L','8','m','C','e','ö','ı','a','1','G','H',
	'M','l','p','2','X','h','j','k','Ö','U','N','Ş','S','c'];
	function mb_chars_replace($from, $to, $subj, $delSymb='_') {
     $nsubj='';
     preg_match_all('/(.)/u', $subj, $subj);$subj=$subj[1];
     if (!is_array($from)) {preg_match_all('/(.)/u', $from, $from);$from=$from[1];} 
     if (!is_array($to)) {preg_match_all('/(.)/u', $to, $to);$to=$to[1];}
     if (count($from)!==count($to)) return false;
     foreach($subj as $s) {
       foreach($from as $k=>$f) {
         if($s===$f) {
                    $s=$to[$k];
                    break;
         }
       }
       if($s!==$delSymb) $nsubj.=$s;
     }
    return $nsubj;
	} 
	function Sifrele($metin,$dosya){
		$metin=$this->mb_chars_replace($this->bundan,$this->buna,$metin);
		file_put_contents($dosya,$metin);
		return $metin;
	}
	function Coz($dosya) {
		return $this->mb_chars_replace($this->buna,$this->bundan, file_get_contents($dosya));
	}
}
$foo = new Sifre;
echo $foo->Sifrele('Merhaba dünya, bu şifreli bir metin!','test.txt');
echo "<br>";
echo $foo->Coz('test.txt');
?>

Çıktısı

Gf4znÇn bZş3n, Ç6 Ruo4fru Çu4 Wf5uş!
Merhaba dünya, bu şifreli bir metin!