• 24-03-2007, 22:16:40
    #1
    Üyeliği durduruldu
    PHP'de yeniyim. İnternette resim upload scripti gördüm ama kod hamallığı varmış gibi geldi bana ve bende en baştan yazmaya çalıştım öğrenmek amacıyla.Şimdide sizinle paylaşıyorum belki işine yarayan çıkar.Thumbnail'de oluşturuyor.

    Resim.php
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
    <title>  Resim Upload </title>
    </head>
    <style type="text/css">
    <!-
    
    .textinput {
        BORDER-RIGHT: #D1DFE6 1px solid;
        PADDING-RIGHT: 2px;
        BORDER-TOP: #D1DFE6 1px solid;
        PADDING-LEFT: 1px;
        FONT-SIZE: 11px;
        PADDING-BOTTOM: 2px;
        BORDER-LEFT: #D1DFE6 1px solid;
        PADDING-TOP: 2px;
        BORDER-BOTTOM: #D1DFE6 1px solid;
        HEIGHT: 14px
    }
    .dosya {
        BORDER-RIGHT: #D1DFE6 1px solid;
        PADDING-RIGHT: 2px;
        BORDER-TOP: #D1DFE6 1px solid;
        PADDING-LEFT: 1px;
        FONT-SIZE: 11px;
        PADDING-BOTTOM: 2px;
        BORDER-LEFT: #D1DFE6 1px solid;
        PADDING-TOP: 2px;
        BORDER-BOTTOM: #D1DFE6 1px solid;
        height: 20px;
    }
    .gonder
    {
        color: #0066FF;
        font: 12px verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;
        border: 0px;
        position:fixed;
    }
    -->
    </style>
    <script language="javascript">
    
    </script>
    <center>
    <?php
    
    
    if(isset($dosya_gonder)){
    session_start();
    if (!empty($_POST["kod"]) || !empty($_SESSION["guv"]) || $_SESSION["guv"]) {
    
     if ($_POST["kod"] == $_SESSION["guv"]) {
    function Create_Thumb($max_width = 0, $max_height = 0,$dosya,$resim_yolu,$thumb) {
    copy($resim_yolu,$thumb) or die("Thumbnail Olusturulamadi..");
    
    if($dosya == "image/pjpeg") {
    $img = imagecreatefromjpeg($thumb);
    }
    else if($dosya == "image/gif") {
    $img = imagecreatefromgif($thumb);
    }
    else if($dosya == "image/png") {
    $img = imagecreatefrompng($thumb);
    }
    $FullImage_width = imagesx($img);
    $FullImage_height = imagesy($img);
    
    $resim_color =  imagecreatetruecolor ($max_width,$max_height);
    imagecopyresampled($resim_color,$img,0,0,0,0,$max_width,$max_height,$FullImage_width,$FullImage_height );
    if($dosya == "image/pjpeg") {
    $full = ImageJPEG( $resim_color, $thumb,100);
    }
    else if($dosya == "image/gif") {
    $full = ImageGIF( $resim_color, $thumb);
    }
    else if($dosya == "image/png") {
    $full = ImagePNG( $resim_color, $thumb);
    }
    imagedestroy($resim_color); 
    unset($max_width); 
    unset($max_height);  
    }
    $dosya_dizin = "c:/apache2triad/htdocs";
    $dizin_url = "http://localhost";
    
    if($max_file_size >= $dosya_gonder_size || $dosya_gonder_size > 0) {
    if($dosya_gonder_type == "image/gif" || $dosya_gonder_type == "image/pjpeg" || $dosya_gonder_type == "image/png"){
    copy($dosya_gonder,$dosya_dizin."/".$dosya_gonder_name) or die("Dosya Kopyalanamadi!");
    $resim_yolu = ($dizin_url."/".$dosya_gonder_name);
    $thumb = ($dosya_dizin."/TH_".$dosya_gonder_name);
    $thumb2 = ($dosya_dizin."/TH2_".$dosya_gonder_name);
    print ("<img src=\"$resim_yolu\">")."<br>";
    Create_Thumb(50,50,$dosya_gonder_type,$resim_yolu,$thumb);
    Create_Thumb(100,100,$dosya_gonder_type,$resim_yolu,$thumb2);
    }
    else { print "Lütfen gif yada jpeg uzantili bir resim dosyasi seçiniz.."; }
    }
    else { print "Dosya boyutu en fazla 2.5 mb olabilir.."; }
      unset($_SESSION["guv"]);
      exit;
     } else {
      echo "Güvenlik Kodu Hatalı Lütfen Yeniden Deneyiniz...";
     }
    }
    }
    else { print "Lütfen bir dosya seçiniz.."; }
    
    ?>
    <body>
    
    <form action="<?= $PHP_SELF ?>" method="post" enctype="multipart/form-data">
    <input class="dosya" type="file" name="dosya_gonder" /><br />
    <img class="resim" style="vertical-align: middle;" src="guvenlik.php"><INPUT class="textinput" NAME="kod" TYPE="text" maxlength="4" ><br/>
    <input class="gonder" type="submit" value="Gönder" />
    <input type="hidden" value="2500000" name="max_file_size" />
    </form>
    </body>
    </center>
    </html>
    Guvenlik.php
     <?
    function olustur () {
     $sifre = substr(md5(rand(0,999999999999)),-4);
     if ($sifre) {
      session_start();
      $_SESSION["guv"] = $sifre;
      $width  = 60;
      $height =  20;
      $resim  = ImageCreate($width,$height);
      $beyaz  = ImageColorAllocate($resim, 255, 255, 255);
      $rand   = ImageColorAllocate($resim, rand(0,255), rand(0,255), rand(0,255));
      ImageFill($resim, 0, 0, $rand);
      ImageString($resim, 5, 10, 2, $_SESSION["guv"], $beyaz);
      ImageLine($resim, 100, 9, 0, 9, $beyaz);
      header("Content,type: image/png");
      ImagePng($resim);
      ImageDestroy($resim);
     }
    }
    olustur();
    ?>
    Yorum yaparsanız sevinirim. ona göre eksiklerimi gideririm.
  • 24-03-2007, 22:21:25
    #2
    Üyeliği durduruldu
    tam oLarak atarmısın:s
  • 24-03-2007, 22:55:34
    #3
    Üyeliği durduruldu
    http://rapidshare.com/files/22605877/resim.rar.html

    Düzeni yok, düzene sokup istediğiniz yere include edebilirsiniz.
  • 24-03-2007, 22:59:39
    #4
    Üyeliği durduruldu
    sağoLasın
  • 25-03-2007, 01:16:53
    #5
    Üyeliği durduruldu
    Teşekkürler.