<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bilgisayar &#187; klasör</title>
	<atom:link href="https://www.bilgisayar.me/index.php/tag/klasor/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bilgisayar.me</link>
	<description></description>
	<lastBuildDate>Wed, 29 Aug 2018 20:31:06 +0000</lastBuildDate>
	<language>tr-TR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.29</generator>
	<item>
		<title>PHP Dosya/Klasör İşlev Örnekleri</title>
		<link>https://www.bilgisayar.me/index.php/2015/06/12/php-dosyaklasor-islev-ornekleri/</link>
		<comments>https://www.bilgisayar.me/index.php/2015/06/12/php-dosyaklasor-islev-ornekleri/#comments</comments>
		<pubDate>Fri, 12 Jun 2015 22:47:02 +0000</pubDate>
		<dc:creator><![CDATA[Hakan Atılgan]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[dosya]]></category>
		<category><![CDATA[klasör]]></category>
		<category><![CDATA[php işlev]]></category>

		<guid isPermaLink="false">http://www.bilgisayar.me/?p=504</guid>
		<description><![CDATA[Bir dizi kes yapıştır PHP klasör ve dosya işlevleri.]]></description>
				<content:encoded><![CDATA[<p>Kes yapıştır PHP klasör ve dosya işlevleri.</p>
<div class="su-note" style="border-color:#dfd5d5;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-clearfix" style="background-color:#f8eded;border-color:#fefbfb;color:#000000;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">Bu sayfadaki örnekleri kullanmadan önce test etmeninizi öneririm.</div></div>
<h3>Bir klasörü ve içindeki bütün dosyaları sil.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Bu işlev klasörü ve içindeki bütün dosyaları siler.
 * $empty = true halinde sadece dosyalar silinir. Klasör silinmez
*/
function hepsiniKaldir($klasor, $empty = false) { 
    if(substr($klasor,-1) == &quot;/&quot;) { 
        $klasor = substr($klasor,0,-1); 
    } 

    if(!file_exists($klasor) || !is_dir($klasor)) { 
        return false; 
    } elseif(!is_readable($klasor)) { 
        return false; 
    } else { 
        $klasorHandle = opendir($klasor); // klasöre git
        
        while ($icerik = readdir($klasorHandle)) {  // klasörü oku
            if($icerik != &#039;.&#039; &amp;&amp; $icerik != &#039;..&#039;) { 
                $path = $klasor . &quot;/&quot; . $icerik; 
                
                if(is_dir($path)) { 
                    hepsiniKaldir($path); 
                } else { 
                    unlink($path); 
                } 
            } 
        } 
        
        closedir($klasorHandle); 

        if($empty == false) { 
            if(!rmdir($klasor)) { 
                return false; 
            } 
        } 
        
        return true; 
    } 
} 
?&gt;
</pre>
<h3>Sadece bir dosya sil.</h3>
<pre class="prettyprint linenums" >
/*
    istenilen dosyayı sil
    $dosyaadi c:\temp\demo\dosya.txt
    dosyasil(&#039;c:\temp\demo\dosya.txt&#039;)
*/
function dosyasil($dosyaadi){
    unlink($dosyaadi);
}
</pre>
<h3>Bir klasör Oluştur.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Bu işlev verilen bir isimle klasör oluşturur.
 * $yeniklasor: klasör ismi
 * $path: klasörün sabit diskteki yeri
 * klasorOlustur(&#039;C:\TEMP&#039;, &#039;phpklasor&#039;); // phpklasor adında yeni bir klasör oluştur
*/

function klasorOlustur($path, $yeniklasor)
{
    if(!is_dir($path.&#039;/&#039;.$yeniklasor))
    {
        return &#039;Geçersiz dizin&#039;; 
    } else if(file_exists($path.$yeniklasor)) {
        return &#039;Klasör mevcut&#039;; 
    } else if(!is_writable($path)) {
        return &#039;Dizin oluşturulamıyor, dizine ulaşma yetkiniz yok&#039;; 
    } else if(mkdir($path.&#039;/&#039;.$yeniklasor) === true){
        return &#039;Dizin başarı ile oluşturuldu&#039;;	 
    }
}
?&gt;
</pre>
<h3>Sadece Klasörleri listele.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Bu işlev sadece klasörleri ul formatinda listeler.
 * kullanimi
 		sadeceKlasorListele(&quot;C:\TEMP&quot;);
*/

function sadeceKlasorListele($dirs) { 
	$empty=true;
	$ul =&#039;&lt;ul&gt;&#039;;
   	foreach(glob($dirs.&#039;/*&#039;, GLOB_ONLYDIR) as $dir){ 
		$dir = basename($dir); 
		$ul .= &#039;&lt;li&gt;&lt;a href=&quot;Javascript:void(0)&quot;&gt;&#039;.$dir.&#039;&lt;/a&gt;&lt;/li&gt;&#039;;
		$empty=false;
	}  
	if ($empty){
		$ul .= &#039;&lt;li&gt;&lt;span&gt;Klasör bulunamadı...&lt;/span&gt;&lt;/li&gt;&#039;;
	}
	$ul .=&#039;&lt;/ul&gt;&#039;;
	return $ul;
	
} 
?&gt;
</pre>
<h3>Sadece dosyaları listele.</h3>
<pre class="prettyprint linenums" >
/*
 * Bu işlev sadece dosyalari ul formatinda listeler.
 * kullanimi
   sadeceDosyaListele(&quot;C:\TEMP&quot;);
*/
function sadeceDosyaListele($dirs) { 
    $ul =&#039;&lt;ul&gt;&#039;;
    if ($handle = opendir($dirs)) { 
        while (false !== ($file = readdir($handle))) {
            if ($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot; &amp;&amp; $file != &quot;Thumb.db&quot; &amp;&amp; $file != &quot;Thumbs.db&quot;) {
                if(is_file($dirs.&#039;/&#039;.$file)){
                    $empty=true;
                    $ul .= &#039;&lt;li&gt;&lt;a href=&quot;Javascript:void(0)&quot;&gt;&#039;.$file.&#039;&lt;/a&gt;&lt;/li&gt;&#039;;
                    $empty=false;
                }
            }
        }
    }
    if ($empty){
        $ul .= &#039;&lt;li&gt;&lt;span&gt;Dosya bulunamadı...&lt;/span&gt;&lt;/li&gt;&#039;;
    }
    $ul .=&#039;&lt;/ul&gt;&#039;;
    return $ul;
} 

</pre>
<h3>Klasör mevcut değilse oluştur.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Klasör varmı diye kontrol et, yoksa oluştur
*/

function klasorYoksaOlustur($path){
	return is_dir($path) || mkdir($path); 
}
?&gt;
</pre>
<h3>Klasördeki bütün dosyaları say.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Klasör içindeki bütün dosyaları sayar ve adeti gösterir
*/

function dosyaSayisi($klasor){
     $sayac = 0;
     if (is_dir($klasor) &amp;&amp; $handle = opendir($klasor)) {
       while (false !== ($file = readdir($handle))) {
           if ($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot; &amp;&amp; $file != &quot;Thumb.db&quot; &amp;&amp; $file != &quot;Thumbs.db&quot;) {
		   	$sayac++;
		   }
       }
       closedir($handle);
     }
     return $sayac;
}

/*
 * Bu işlev ise öznitelikli(recursive) olarak dosyaları sayar
   kullanımı:
	$dosyaadedi = dosyaSayisi(&quot;/home/klasor&quot;, true); // alt klasörlerde dahil olmak üzere bütün dosyaları sayar.
	$dosyaadedi = dosyaSayisi(&quot;/tmp&quot;); // /tmp klasöründekı dosyaları sayar. Alt klasörler ve içlerindeki dosyalar sayılmaz.
*/
function dosyaSayisi($klasor, $recursive=false, $sayac=0) {
     static $sayac;
     if(is_dir($klasor)) {
       if($dh = opendir($klasor)) {
         while(($dosya = readdir($dh)) !== false) {
           if($dosya != &quot;.&quot; &amp;&amp; $dosya != &quot;..&quot;) {
               $sayac = (is_dir($klasor.&quot;/&quot;.$dosya)) ? dosyaSayisi($klasor.&quot;/&quot;.$dosya, $recursive, $sayac) : $sayac+1;
           }
         }
         closedir($dh);
       }
     }
     return $sayac;
   }
?&gt;
</pre>
<h3>Bir klasörün kapasitesini bul.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Bu işlev klasörün kapasıtesini bulur.
*/

function klasorKapasitesi($klasor){
    $kapasite = 0;
    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($klasor)) as $dosya) {
        $kapasite += $dosya-&gt;getSize();
    }
    return $kapasite;
}
?&gt;
</pre>
<h3>Bir klasörün içinden gelişi güzel resim dosyası seç.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
/*
 * Bu işlev klasörün içinden gelişi güzel bir resim dosyası seçer.
*/

function gelisiGuzelResimSec(){
    $klasor = &#039;upload/&#039;;
    $images = glob($klasor . &#039;*.{jpg,jpeg,png,gif}&#039;, GLOB_BRACE);
    if ($images[array_rand($images)] != &#039;&#039;){
	   return $images[array_rand($images)]; // See comments
    } else {
	   return &#039;upload/resimbulunamadi.jpg&#039;;	
    }
}
?&gt;
</pre>
<h3>Bir dosyanın uzantısını bul.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
function dosyaUzantisiniBul($str) {
    $i = strrpos($str,&quot;.&quot;);
    if (!$i) { return &quot;&quot;; } 
    $l = strlen($str) - $i;
    $ext = substr($str,$i+1,$l);
    return $ext;
}
?&gt;
</pre>
<h3>Bir dosyanın kapasitesinin formatlanması.</h3>
<pre class="prettyprint linenums" >
&lt;?PHP
function formatKapasite($kapasite) {
    $kapasiteler = array(&quot; Byte&quot;, &quot; KB&quot;, &quot; MB&quot;, &quot; GB&quot;, &quot; TB&quot;, &quot; PB&quot;, &quot; EB&quot;, &quot; ZB&quot;, &quot; YB&quot;);
    if ($kapasite == 0) { 
	   	return; 
	} else {
       return (round($kapasite/pow(1024, ($i = floor(log($kapasite, 1024)))), $i &gt; 1 ? 2 : 0) . $kapasiteler[$i]); 
	}
 }
 ?&gt;
</pre>
<h3>Yerel dosyayı oku.</h3>
<pre class="prettyprint linenums" >
/*
   text dosyasını oku
       yereldosyaoku($dosyaadi); // c:\temp\demo\dosya.txt
*/
function yereldosyaoku($dosya) {
    return file_get_contents($dosya);
}
</pre>
<h3>Yerel dosyayı kaydet.</h3>
<pre class="prettyprint linenums" >
/*
    değiştirilen dosyayı kaydet
        yereldosyakaydet($dosyamevki, &amp;$data, $ekle= false); // // $dosyamevki c:\temp\demo\dosya.txt
*/
function yereldosyakaydet($dosyamevki, &amp;$data, $ekle= false) {
	if($ekle) { / dosyaya ekle yoksa yeniden yaz
		return file_put_contents($dosyamevki, $veri, FILE_APPEND);
	}
	return file_put_contents($dosyamevki, $veri);
}

</pre>
<h3>Dosyayı kopyala.</h3>
<pre class="prettyprint linenums" >
/*
    not: eğer aynı isimde başka bir dosya mevcutsa, yenisi ile değiştirilir.
    dosyakopyala(&#039;c:&#039;temp\1\eskidosya.txt&#039;,&#039;c:\temp\2\yenidosya.txt&#039;);
*/
function dosyakopyala($dosya,$yenidosya) { 
    copy($dosya, $yenidosya);
}
</pre>
<h3>Dosyayı başka bır yere taşı.</h3>
<pre class="prettyprint linenums" >
/*
    dosyayi yeni mevkiye taşı ve öncekini sil
    dosyatasi(&#039;c:&#039;temp\1\eskidosya.txt&#039;,&#039;c:\temp\2\eskidosya.txt&#039;);
*/
function dosyatasi($dosyaadi,$yenidosya) { 
	copy($dosyaadi, $yenidosya); //
	unlink($dosyaadi); // eskidosya.txt kaldırıldı
}
</pre>
<h3>X günden önceki tüm dosyaları sil</h3>
<pre class="prettyprint linenums" >
/*
    X günden önce oluşturulmuş bütün dosyaları sil
    eskiDosyalariSil(&#039;C:\TEMP&#039;,5); //temp klasörünün içindeki 5 günden önce oluşturulmuş bütün dosyaları siler
*/
function eskiDosyalariSil($klasör,$gun){
    if (file_exists($klasör)) {
        foreach (new DirectoryIterator($klasör) as $dosya) {
            if ($dosya-&gt;isDot()) {
                continue;
            }
            if (time() - $dosya-&gt;getCTime() &gt;= $gun*24*60*60) {
                unlink($dosya-&gt;getRealPath());
            }
        }
    }
}
</pre>
<h3>Dosya uzantısını bul</h3>
<pre class="prettyprint linenums" >
// kullanımı dosyaUzantisi(&quot;dosya.doc&quot;); 
function dosyaUzantisi($dosya){
    return pathinfo($dosya, PATHINFO_EXTENSION);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.bilgisayar.me/index.php/2015/06/12/php-dosyaklasor-islev-ornekleri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
