Php Imap E-Mail Dosya Eklerini İndirme

Aşağıdaki kod ile gelen kutunuzda bulunan tüm e-maillerdeki dosya eklerini toplu olarak indirebilirsiniz. Dilerseniz for döngüsü yerine $x’e sabit bir değer vererek tek bir dosya ekini de indirebilirsiniz.

<?php
header('Content-Type: text/html; charset=utf-8');
$stream = imap_open('{mail.site.com:143/novalidate-cert}INBOX','admin@site.com', '123456');
$numMessages = imap_num_msg($stream);
for($x=$numMessages;$x>0;$x--){
	$structure=imap_fetchstructure($stream,$x);
	if(isset($structure->parts)) {
		foreach ($structure->parts as $index => $part){
			if (!$part->ifdisposition) continue;
			$body=imap_fetchbody($stream,$x, $index + 1);
			if($part->encoding==3) $body=base64_decode($body);
			if($part->encoding==4) $body=imap_qprint($body);
			$savePath = 'attachments/'.imap_utf8($part->dparameters[0]->value);
			file_put_contents($savePath, $body);
		}
	}
}


Php ile Whatsapp grupta kim kaç mesaj atmış uygulaması

<?php 
header('Content-Type: text/html; charset=utf-8');
$fh = fopen('wp.txt','r');//whatsapp grup mesaj yedeği dosya adı
$data=array();
echo "<pre>";
while ($line = fgets($fh)) {
	preg_match('@(\d{2}).(\d{2}).(\d{4}) (\d{2}):(\d{2}) - (.*?): (.*?)@si',$line,$l);
	if(isset($l[6])){
		$data[]=$l[6];
	}
}
$a = array_count_values($data);
arsort($a);
print_r($a);
fclose($fh);
?>

Whatsapp gruplarında dışa aktardığınız yazışmayı wp.txt olarak localhost ana dizinine kaydetmeniz gerekir.

//Çıktısı:
Array
(
    [Mehmet] => 3192
    [Ahmet] => 2060
    [Ali] => 1906
    [Ayşe] => 1771
    [Fatma] => 1350
    [Veli] => 1191
)

Php ile Lynch-Bell Sayılarını Bulmak (Algoritmik Çözüm)

<?php
error_reporting(0);//sıfıra bölme hatası bastırma
	//Php ile Lynch-Bell Sayılarını Bulmak
	//açıklayıcı algoritmalı çözüm
	for($x=10000;$x<100000;$x++){//5 basamaklı sayıları örnek alacak olursak
		$s1=$x%10;//birler basamağını (mod10)
		$s2=floor(($x%100)/10);//onlar basamağı aşağıyuvarla(mod yüz/10)
		$s3=floor(($x%1000)/100);//yüzler basamağı aşağıyuvarla(mod bin/10)
		$s4=floor(($x%10000)/1000);//binler basamağı aşağıyuvarla(mod bin/10)
		$s5=floor($x/10000);//on binler basamağı aşağıyuvarla(x/1000)
			
		if($x%$s1 == 0){//birler basamağı mod
			if($x%$s2 == 0){//onlar basamağı mod
				if($x%$s3 == 0){//yüzler basamağı mod
					if($x%$s4 == 0){//binler basamağı mod
						if($x%$s5 == 0){//on binler basamağı mod
						  echo $x."<br>";
						}
					}
				}
			}
		}		
	}
?>

Mysql 1364 Field doesn’t have a default value hatası çözümü

Phpmyadmin güncellemesi ile birlikte bu hatayı alanlar uyarıda geçen tabloya tıkladıktan sonra Yapı menüsünden ilgili sütunu seçerek Yapı linkine tıklayın.

Varsayılan değeri yok olan AutoIncrement(id) hariç olan sütunları değiştir seçeneğine tıklayın

Varsayılan değer olarak NULL veya tanımlı bir değer girerek kaydedin.

Php Base Url Fonksiyonu

Php config sayfanıza aşağıdaki kodu ekleyip html sayfanızdaki url ve linklerin başına bu fonksiyonu ekleyebilirsiniz.

function baseurl(){
	return str_replace(
		$_SERVER["DOCUMENT_ROOT"],"",str_replace(
			str_replace(
				$_SERVER["REQUEST_URI"],"",str_replace(
					"\\","/",$_SERVER["SCRIPT_FILENAME"]
				)
			),"",str_replace(
				"\\","/",dirname(__FILE__)
			)
		)
	)."/";
}
//Örnek Kullanımı
echo baseurl()."css/style.css";

Ana dizinde config.php dosyasi bulunduğu varsayılarak bu kodlar config.php içine eklendiğinde config.php dosyasının require ve include ile dahil edildiği tüm dosya ve dizinlerde config.php nin bulunduğu dizini base olarak almaktadır.

Resim Yükleme ve Boyutlandırma Sınıfı

<?php
header('Content-Type: text/html; charset=utf-8');
class resimYukleyici{
	public $isim;
	public $tip;
	public $boyut;
	public $gecici;
	public $hata;
	public $resim;
	public $kucukresim;
	public $mesaj;
	public $yeniresim;
	public $yenikucukresim;
	public function __construct(){
		global $_FILES;
		$this->hata = $_FILES['image']['error'];
		if($this->hata != 0){
			$this->mesaj = $this->hata;
			$this->mesaj;
			return false;
		}else{
			$this->isim = $_FILES['image']['name'];
			$this->tip = $_FILES['image']['type'];
			$this->boyut = $_FILES['image']['size'];
			$this->gecici = $_FILES['image']['tmp_name'];
			return true;
		}
	}
	public function validate($maxdosyaboyutu,$minresimboyutu){
		if($this->tip != 'image/jpeg' && $this->tip != 'image/gif' && $this->tip != 'image/png'){
			$this->mesaj = 'Hatali dosya formati.';
			return false;
		}
		if($this->boyut > $maxdosyaboyutu){
			$this->mesaj = 'Dosya cok buyuk.';
			return false;
		}
		$boyut = getimagesize($this->gecici);
		if($boyut[0] < $minresimboyutu || $boyut[1] < $minresimboyutu){
			$this->mesaj = 'boyutlar cok kucuk.';
			return false;
		}else{
			return true;
		}
	}
	public function kirp($maxBoyut, $maxKucukBoyut){
		list($orjinalgenislik, $orjinalyukseklik) = getimagesize($this->gecici);
		if($orjinalgenislik > $orjinalyukseklik){
			$genislik = $maxBoyut;
			$yukseklik = intval($maxBoyut*($orjinalyukseklik/$orjinalgenislik));
			$kucukgenislik = $maxKucukBoyut;
			$kucukyukseklik = intval($maxKucukBoyut*($orjinalyukseklik/$orjinalgenislik));
		}else if($orjinalgenislik < $orjinalyukseklik){
			$genislik = intval($maxBoyut*($orjinalgenislik/$orjinalyukseklik));
			$yukseklik = $maxBoyut;
			$kucukgenislik = intval($maxKucukBoyut*($orjinalgenislik/$orjinalyukseklik));
			$kucukyukseklik = $maxKucukBoyut;
		}else{
			$genislik = $maxBoyut;
			$yukseklik = $maxBoyut;
			$kucukgenislik = $maxKucukBoyut;
			$kucukyukseklik = $maxKucukBoyut;
		}
		$this->resim = imagecreatetruecolor($genislik,$yukseklik);
		$this->kucukresim = imagecreatetruecolor($kucukgenislik, $kucukyukseklik);
		if($this->tip == 'image/gif'){
			$kaynakresim = imagecreatefromgif($this->gecici);
		}else if($this->tip == 'image/jpeg'){
			$kaynakresim = imagecreatefromjpeg($this->gecici);
		}else{
			$kaynakresim = imagecreatefrompng($this->gecici);
		}
		imagecopyresampled($this->resim,$kaynakresim,0,0,0,0,$genislik,$yukseklik,$orjinalgenislik,$orjinalyukseklik);
		imagecopyresampled($this->kucukresim,$kaynakresim,0,0,0,0,$kucukgenislik,$kucukyukseklik,$orjinalgenislik,$orjinalyukseklik);
		
	}
	public function yukle($dizin,$kalite){
		$uzanti = explode('.',$this->isim);
		$isim=date("YmdHis").rand(1,100);
		$this->yeniresim = $isim.'.'.$uzanti[1];
		$this->yenikucukresim = $isim.'kucuk.'.$uzanti[1];
		if($this->tip == 'image/gif'){
			imagegif($this->resim, ($dizin.$this->yeniresim));
			imagegif($this->kucukresim, $dizin.$this->yenikucukresim);
		}
		else if($this->tip == 'image/jpeg'){
			imagejpeg($this->resim, $dizin.$this->yeniresim, $kalite);
			imagejpeg($this->kucukresim, $dizin.$this->yenikucukresim, $kalite);
		}
		else{
			imagepng($this->resim,$dizin.$this->yeniresim);
			imagepng($this->kucukresim,$dizin.$this->yenikucukresim);
		}
		$this->mesaj = 'Dosya yuklendi.';
	}
}
if (isset($_POST['yukle'])){
	$dizin=dirname(__FILE__)."/";
	$i=new resimYukleyici;
	$i->kirp(250,250);
	$i->yukle($dizin ,100);
	echo $i->yeniresim.'<br>';
	echo '<img src="/'.$i->yeniresim.'">';
}else{
	echo '<form action="" method="post" enctype="multipart/form-data">
  <input type="file" name="image">
  <input type="submit" name="yukle" value="Yükle">
	</form>';
}
?>

Çıktısı

2018062622193729.png

HTML Liste Sınıfı

<?php
header('Content-Type: text/html; charset=utf-8');
class HTML_Liste {
	var $link,$link_baslik,$font,$renk,$tip,$bg_renk;
	var $dizi = array();
	function HTML_Liste($dizi,$font,$renk,$bg_renk,$tip){
		$this->dizi = $dizi;
		$this->font = $font;
		$this->renk = $renk;
		$this->tip = $tip;
		$this->bg_renk = $bg_renk;
	}
	function goster(){
		echo "<ul style='padding-top:5px;padding-bottom:5px;background-color:$this->bg_renk;list-style-type:".$this->tip."' >";
		foreach($this->dizi as $link=>$link_baslik){
			echo "<a style='text-decoration:none;' href='$link'><li style='padding-top:1px;font-family:verdana; color:$this->renk; font-size:8pt font-style:bold;'>$link_baslik</li></a>";
		}
		echo "</ul>";
	}
}
$links = array("og.php"=>"Özgeçmiş","bilgi.php"=>"Bilgi","kurslar.php"=>"Kurslar");
$html_list = new HTML_Liste($links,'sans-serif','black','orange','disc');
$html_list->goster();
?>

Çıktısı

Saat Farkı Ekleme Çıkarma Sınıfı

<?php
class zamanDamgasi {
  var $deger = '';
  var $fark = 0;
	var $bicim="d.m.Y H:i:s";
  function zamanDamgasi($deger='') {
		date_default_timezone_set('Europe/Istanbul');
    if ($deger) {
      $this->deger = $deger;
    }else {
      $this->deger = time();
    }
  }
  function yenisaat() {
    $deger = $this->deger;
    $bicim = $this->bicim;
    if ($this->fark) {
      $saniye = $this->fark*60*60;
      $deger = $deger + ($saniye);
    }
    return date($bicim,$deger);
  }
  function mevcutsaat() {
	$deger = $this->deger;
    $bicim = $this->bicim;
    return date($bicim,$deger);
  }
  function saatFarkiEkleCikar($deger) {
    $this->fark = $deger;
  }
}
$ts = new zamanDamgasi;
$ts->saatFarkiEkleCikar(-1);
echo $ts->mevcutsaat();
echo "<br>";
echo $ts->yenisaat();
?>

Çıktısı

26.06.2018 18:21:34
26.06.2018 17:21:34

 

Mcrypt ile Şifreleme Sınıfı

<?php
header('Content-Type: text/html; charset=iso-8859-9');
class SifreleCoz {
	var $anahtar;
	var $veri;
	var $td;
	var $iv;
	var $bas = false;
	function SifreleCoz($anahtar='',$veri=''){
		if ($anahtar != ''){
			$this->bas($anahtar);			
		}
		$this->veri = $veri;
	}
	function bas(&$anahtar){
		$this->td = mcrypt_module_open ('des', '', 'ecb', ''); 
		$this->anahtar = substr ($anahtar, 0, mcrypt_enc_get_key_size($this->td)); 
		$iv_boyut = mcrypt_enc_get_iv_size($this->td); 
		$this->iv = mcrypt_create_iv($iv_boyut, MCRYPT_RAND);
		$this->bas = true;
	}
	function anahtarAyarla($anahtar){
		$this->bas($anahtar);
	}
	function veriAyarla($veri){
		$this->veri = $veri;
	}
	function &anahtarGetir(){
		return $this->anahtar;
	}
	function &veriGetir(){
		return $this->veri;
	}
	function &sifrele($veri=''){
		return $this->_sifre('sifrele',$veri);
	}
	function &coz($veri=''){
		return $this->_sifre('coz',$veri);
	}
	function kapat(){
		mcrypt_module_close($this->td); 
	}
	function &_sifre($mode,&$veri){
		if ($veri != ''){
			$this->veri = $veri;
		}
		if ($this->bas){
			if (mcrypt_generic_init($this->td,$this->anahtar,$this->iv) != -1){ 
				if ($mode == 'sifrele'){
					$this->veri = mcrypt_generic($this->td, $this->veri); 
				}elseif($mode == 'coz'){
					$this->veri = mdecrypt_generic($this->td, $this->veri); 
				}
				mcrypt_generic_deinit($this->td);
				return $this->veri;
			}else{
				trigger_error('Error basialising '.$mode.'ion handle',E_USER_ERROR);
			}
		}else{
			trigger_error('Key not set. Use anahtarAyarla() method',E_USER_ERROR);
		}
	}
}
$sc = new SifreleCoz('gizli anahtar');
$kullanici = 'kullanici';
$sifre = 'sifre';
$s_kullanici = $sc->sifrele($kullanici);
$s_sifre = $sc->sifrele($sifre);
echo 'sifreli kullanici: '.$s_kullanici;
echo '<br>';
echo 'sifreli sifre: '.$s_sifre;
echo '<br>';
echo 'sifresiz kullanici: '.$sc->coz($s_kullanici);
echo '<br>';
echo 'sifresiz sifre: '.$sc->coz($s_sifre);
echo '<br>';
$sc->kapat();
?>

Çıktısı

sifreli kullanici: £ÈÄN/©„İ­ÂÒñ£
sifreli sifre: rtï§ğ
sifresiz kullanici: kullanici
sifresiz sifre: sifre