PHP Code [Library]

Discussion in 'PHP' started by soyturk, Jan 28, 2007.

  1. #1
    File Upload :

    <? 
        ## Bu bir açık kaynak kodudur 
        ## Bu kod Ali Soyturk Tarafından 22.01.2007 tarihinde yazılmıştır 
        ## Kodların bağlı olduğu web sitesi www.soyturk.com dur 
        ## Bu kod hakkındaki soru ve önerilerinizi ali[at]soyturk.com adresine bildiriniz 
        ## Kolay gelsin 
         
        // HTML Formumuz; 
        echo '<script language="Javascript">'."\n"; 
        echo 'function disableIt(obj)'."\n"; 
        echo '{'."\n"; 
        echo '    obj.disabled = !(obj.disabled);'."\n"; 
        echo '    var z = (obj.disabled) ? \'disabled\' : \'enabled\';'."\n"; 
        echo '}'."\n"; 
        echo '</script>'."\n"; 
        echo '<pre>'."\n"; 
        echo '<form name="formum" method="POST" enctype="multipart/form-data" action="file_upload.php"> '."\n"; 
        echo 'Resim 1    : <input type="file" name="resim1" id="resim" disabled>'; 
        echo ' <input type="checkbox" name="rsm1" value="1" onclick="javascript:disableIt(document.forms[0].resim1)">'."\n"; 
        echo 'Resim 2    : <input type="file" name="resim2" id="resim" disabled>'; 
        echo ' <input type="checkbox" name="rsm2" value="1" onclick="javascript:disableIt(document.forms[0].resim2)">'."\n"; 
        echo 'Resim 3    : <input type="file" name="resim3" id="resim" disabled>';  
        echo ' <input type="checkbox" name="rsm3" value="1" onclick="javascript:disableIt(document.forms[0].resim3)">'."\n"; 
        echo '      <input type="submit" value="Resimleri Yolla">'."\n"; 
        echo '</form> '."\n"; 
        echo '</pre>'."\n"; 
         
         
        // Post Edildikten sonra iÅŸelenecek iÅŸlemler. 
        if($_POST) { 
                $dizin    = 'upload/'; // dosyaların upload edileceği klasor. CHMOD 777 yapınız 
                $rsmad    = time(); 
                if($_POST["rsm1"] == '1'){ 
                    $path_b    = pathinfo($_FILES['resim1']['name']); 
                    $rsm1ad    = $rsmad.'-a.'.$path_b['extension']; // Resim 1  Yeni Adı 
                    $resim1 = $dizin.$rsm1ad;   
                    @copy($_FILES["resim1"]["tmp_name"],$resim1) or die('Resim1 Eklenemedi'); 
                } 
                if($_POST["rsm2"] == '1'){ 
                    $path_b    = pathinfo($_FILES['resim2']['name']); 
                    $rsm2ad    = $rsmad.'-b.'.$path_b['extension']; // Resim 2  Yeni Adı 
                    $resim2 = $dizin.$rsm2ad;  
                    @copy($_FILES["resim2"]["tmp_name"],$resim2) or die('Resim2 Eklenemedi'); 
                } 
                if($_POST["rsm3"] == '1'){ 
                    $path_b    = pathinfo($_FILES['resim3']['name']); 
                    $rsm3ad    = $rsmad.'-c.'.$path_b['extension']; // Resim 3  Yeni Adı 
                    $resim3 = $dizin.$rsm3ad;  
                    @copy($_FILES["resim3"]["tmp_name"],$resim3) or die('Resim3 Eklenemedi'); 
                } 
        } 
    ?> 
    
    PHP:
     
    soyturk, Jan 28, 2007 IP
    vishwaa likes this.
  2. soyturk

    soyturk Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    Digital Goods:
    1
    #2
    Real IP Adress
    <? 
        ## Bu bir açık kaynak kodudur 
        ## Bu kod Ali Soyturk Tarafından 22.01.2007 tarihinde yazılmıştır 
        ## Kodların bağlı olduğu web sitesi www.soyturk.com dur 
        ## Bu kod hakkındaki soru ve önerilerinizi ali[at]soyturk.com adresine bildiriniz 
        ## Kolay gelsin 
    
        function real_ip_adress() { 
            global $HTTP_SERVER_VARS;  
            $gizli_ipler = array( '10.0.0.', '192.168.', '127.0.0.', '172.16.0.' );  
            if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '' ) {  
                $ip_strings = explode( ',',$_SERVER['HTTP_X_FORWARDED_FOR']);  
                    foreach($ip_strings as $k => $v) { 
                        if( empty($v) ) { 
                            unset( $ip_strings[$k] );  
                        } else { 
                            if(!isset($ip_string)) {  
                                $ip_string = $v;  
                            }  
                        }  
                    }  
            }  
            if( isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '' ) {  
                $ip_strings[] = $_SERVER['REMOTE_ADDR'];  
                    if(!isset($ip_string)) { 
                        $ip_string = $_SERVER['REMOTE_ADDR']; 
                    }  
            }  
            foreach($ip_strings as $k1 => $ip) { 
                foreach($gizli_ipler as $k2 => $pip) {  
                    if(strpos($ip, $pip) === 0) {  
                        unset($ip_strings[$k1]); break;  
                    }  
                }  
            }  
            if(!empty($ip_strings) ) {  
                foreach( $ip_strings as $v ) { 
                    if(!empty($v)) {  
                        $ip_string = $v;  
                        $is_local_ip = false;  
                        break;  
                    } 
                } 
            } else {  
                $is_local_ip = true; 
            }  
            return $ip_string;  
        } 
        $ip    = real_ip_adress(); 
         
        //  echo 'IP Adresi : '.$ip; 
    ?> 
    PHP:
     
    soyturk, Jan 28, 2007 IP
  3. soyturk

    soyturk Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    Digital Goods:
    1
    #3
    read Xml

    <?  
        ## Bu bir açık kaynak kodudur 
        ## Bu kod Ali Soyturk Tarafından 22.01.2007 tarihinde yazılmıştır 
        ## Kodların bağlı olduğu web sitesi www.soyturk.com dur 
        ## Bu kod hakkındaki soru ve önerilerinizi ali[at]soyturk.com adresine bildiriniz 
        ## Kolay gelsin 
         
        $veri    = array();   
        $kaynak    = @file_get_contents("http://www.cnnturk.com/servisler/rss/anasayfa.rss");   
        $temp    = @split("<item>",$kaynak); 
        $h_say    = @count($temp); 
        for ($i = 1; $i <= $h_say; $i++) {   
            if(trim($temp[$i])=='') { 
                continue; 
            }   
                @preg_match('/<title>(.*)<\/title>/i', $temp[$i], $baslik);   
                @preg_match('/<description>(.*)<\/description>/i', $temp[$i], $yazi);   
                @preg_match('/<link>(.*)<\/link>/i', $temp[$i], $link);   
                @preg_match('/<pubDate>(.*)<\/pubDate>/i', $temp[$i], $zaman);   
                @array_push($veri,array($baslik[1],$yazi[1],$link[1],$zaman[1]));   
        }  
        for($x = 0; $x <= ($h_say-2); $x++) { 
            $h_baslik    = $veri[$x][0]; 
            $h_detay    = $veri[$x][1]; 
            $h_link        = $veri[$x][2]; 
            $h_zaman    = $veri[$x][3]; 
            echo '<ul>'."\n"; 
            echo '    <li>'; 
                echo '<a href="'.$h_link.'">'."\n"; 
                echo '<b>'.$h_baslik.'</b></a> '.$h_zaman.'<br>'."\n"; 
                echo $h_detay."\n"; 
            echo '    </li>'; 
            echo '</ul>'."\n"; 
        }  
    ?>  
    PHP:
     
    soyturk, Jan 28, 2007 IP
  4. soyturk

    soyturk Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    Digital Goods:
    1
    #4
    .Dir List
    <? 
        ## Bu bir açık kaynak kodudur 
        ## Bu kod Ali Soyturk Tarafından 22.01.2007 tarihinde yazılmıştır 
        ## Kodların bağlı olduğu web sitesi www.soyturk.com dur 
        ## Bu kod hakkındaki soru ve önerilerinizi ali[at]soyturk.com adresine bildiriniz 
        ## Kolay gelsin 
    
    	function listdir($yol) { 
    		$dizinac = opendir($yol); 
    		while ( gettype ($dizin = readdir($dizinac) ) != boolean ) { 
    			if ( is_dir("$yol/$dizin") ) { 
    				if ( ($dizin != ".") AND ($dizin != "..") ) { 
    					echo (ucwords($dizin)."<br>"); 
    				} 
    			} 
    		} 
    		closedir ($dizinac); 
    	}
    	
    	@listdir("./x");
    	
    ?> 
    PHP:
     
    soyturk, Jan 28, 2007 IP
  5. soyturk

    soyturk Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    Digital Goods:
    1
    #5
    File List
    <? 
        ## Bu bir açık kaynak kodudur 
        ## Bu kod Ali Soyturk Tarafından 22.01.2007 tarihinde yazılmıştır 
        ## Kodların bağlı olduğu web sitesi www.soyturk.com dur 
        ## Bu kod hakkındaki soru ve önerilerinizi ali[at]soyturk.com adresine bildiriniz 
        ## Kolay gelsin 
    
    	function filelist($yol) { 
    		$dizinac = opendir($yol); 
    		while ( gettype ($dosya = readdir($dizinac) ) != boolean ) { 
    			if ( is_file("$yol/$dosya") ) { 
    					echo (ucwords($dosya)."<br>"); 
    			} 
    		} 
    		closedir ($dizinac); 
    	} 
    
    	@filelist("./x");
    ?> 
    PHP:
     
    soyturk, Jan 28, 2007 IP
  6. soyturk

    soyturk Active Member

    Messages:
    112
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    Digital Goods:
    1
    #6
    File List Order By ABC
    <? 
        ## Bu bir açık kaynak kodudur 
        ## Bu kod Ali Soyturk Tarafından 22.01.2007 tarihinde yazılmıştır 
        ## Kodların bağlı olduğu web sitesi www.soyturk.com dur 
        ## Bu kod hakkındaki soru ve önerilerinizi ali[at]soyturk.com adresine bildiriniz 
        ## Kolay gelsin 
    	function file_list_abc($dizin) {
    		$dizi    = array();
    		$ac    = opendir($dizin); 
    		while($x=readdir($ac)) { 
    			if ($x != "." && $x != "..") { 
    				$dizi[] = $x; 
    			} 
    		} 
    		sort($dizi); // List ABC.
    		echo("<table border=0>"); 
    		foreach($dizi as $x => $y) { 
    			echo("<tr><td><b>$x.<b></td><td>$y</td></tr>"); 
    		}
    		echo("</table><br>"); 
    		echo("toplam dosya: "); 
    		echo "<b>".count($dizi)."</b>";
    		closedir($ac);
    	}
    	@file_list_abc("./x");
    ?> 
    PHP:
     
    soyturk, Jan 28, 2007 IP