İçeriğe geç
ShiftDelete.Net
Haber ara/ SDN'ye SorGiriş
Haber Akışı SDNTV İnceleme Forum Yapay Zeka Akıllı Telefon Elektrikli Otomobil Oyun ShiftDelete.Net Global Teknoloji Haberleri Mobil Otomobil Donanım Savunma Bilim Sosyal Medya İnternet Giyilebilir Teknoloji Rehber Ürünler Son dakika Yazarlar
  1. Ana sayfa
  2. Topluluk
  3. Programlama
  4. Web Programlama (PHP, ASP, HTML, CSS, JavaScript)
Web Programlama (PHP, ASP, HTML, CSS, JavaScript)

Php resim upload acil

javascript:??28.08.20097 cevap2.289 görüntüleme
2008'den beri165 mesaj
#1
nasıl ypaarım bunu?

html formdan dosya seçilecek ve resimler/ dizinine benzersiz bir isimle yüklenecek sanırım uniqid ile yapılıyor ama detayları bilmiyorum hemen çok kısa bir şekilde yazarmısınız nasıl upload sistemi yaparım?
Cevaplar
2008'den beri4.262 mesaj
#2
EDIT: geldim :thumbup:

resim yükleme fonksiyonu bu fonksiyonların hepsi bağlı çalışır. Biraz inceleyip düzenleye bilirsin.

HTML dosyasındaki dosya yükleme alanının adını fleImage yap.

$catImage = uploadImage('[B]fleImage[/B]', "images/");

function uploadImage($inputName, $uploadDir)
{
    $image     = $_FILES[$inputName];
    $imagePath = '';
    $max_image_width="150";
    
    if (trim($image['tmp_name']) != '') 
    {
           $ext = substr(strrchr($image['name'], "."), 1); 
           $imagePath = md5(rand() * time()) . ".$ext";
        
        $size = getimagesize($image['tmp_name']);    
        
        if ($size[0] > $max_image_width) 
        {
        $imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, $max_image_width);
        } 
        else 
        {
        if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) 
            {
            $imagePath = '';
            }
        }    
    }
return $imagePath;
}
function createThumbnail($srcFile, $destFile, $width, $quality = 100)
{
    $thumbnail = '';
    
    if (file_exists($srcFile)  && isset($destFile))
    {
        $size        = getimagesize($srcFile);
        $w           = number_format($width, 0, ',', '');
        $h           = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
        
        $thumbnail =  copyImage($srcFile, $destFile, $w, $h, $quality);
    }
    
    // return the thumbnail file name on sucess or blank on fail
    return basename($thumbnail);
}

/*
    Copy an image to a destination file. The destination
    image size will be $w X $h pixels
*/
function copyImage($srcFile, $destFile, $w, $h, $quality = 75)
{
    $tmpSrc     = pathinfo(strtolower($srcFile));
    $tmpDest    = pathinfo(strtolower($destFile));
    $size       = getimagesize($srcFile);

    if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
    {
       $destFile  = substr_replace($destFile, 'jpg', -3);
       $dest      = imagecreatetruecolor($w, $h);
    } 
    elseif ($tmpDest['extension'] == "png") 
        {
       $dest = imagecreatetruecolor($w, $h);
    } 
    else 
    {
      return false;
    }

    switch($size[2])
    {
       case 1:       //GIF
           $src = imagecreatefromgif($srcFile);
           break;
       case 2:       //JPEG
           $src = imagecreatefromjpeg($srcFile);
           break;
       case 3:       //PNG
           $src = imagecreatefrompng($srcFile);
           break;
       default:
           return false;
           break;
    }

    imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);

    switch($size[2])
    {
       case 1:
       case 2:
           imagejpeg($dest,$destFile, $quality);
           break;
       case 3:
           imagepng($dest,$destFile);
    }
    return $destFile;

}

javascript:?? Konuyu açan
2008'den beri165 mesaj
#3
.......
javascript:?? Konuyu açan
2008'den beri165 mesaj
#4
kaberdey dedi: ↑
EDIT: geldim :thumbup:

resim yükleme fonksiyonu bu fonksiyonların hepsi bağlı çalışır. Biraz inceleyip düzenleye bilirsin.

HTML dosyasındaki dosya yükleme alanının adını fleImage yap.

$catImage = uploadImage('[B]fleImage[/B]', "images/");
 
function uploadImage($inputName, $uploadDir)
{
    $image     = $_FILES[$inputName];
    $imagePath = '';
    $max_image_width="150";
 
    if (trim($image['tmp_name']) != '') 
    {
           $ext = substr(strrchr($image['name'], "."), 1); 
           $imagePath = md5(rand() * time()) . ".$ext";
 
        $size = getimagesize($image['tmp_name']);    
 
        if ($size[0] > $max_image_width) 
        {
        $imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, $max_image_width);
        } 
        else 
        {
        if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) 
            {
            $imagePath = '';
            }
        }    
    }
return $imagePath;
}
function createThumbnail($srcFile, $destFile, $width, $quality = 100)
{
    $thumbnail = '';
 
    if (file_exists($srcFile)  && isset($destFile))
    {
        $size        = getimagesize($srcFile);
        $w           = number_format($width, 0, ',', '');
        $h           = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
 
        $thumbnail =  copyImage($srcFile, $destFile, $w, $h, $quality);
    }
 
    // return the thumbnail file name on sucess or blank on fail
    return basename($thumbnail);
}
 
/*
    Copy an image to a destination file. The destination
    image size will be $w X $h pixels
*/
function copyImage($srcFile, $destFile, $w, $h, $quality = 75)
{
    $tmpSrc     = pathinfo(strtolower($srcFile));
    $tmpDest    = pathinfo(strtolower($destFile));
    $size       = getimagesize($srcFile);
 
    if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
    {
       $destFile  = substr_replace($destFile, 'jpg', -3);
       $dest      = imagecreatetruecolor($w, $h);
    } 
    elseif ($tmpDest['extension'] == "png") 
        {
       $dest = imagecreatetruecolor($w, $h);
    } 
    else 
    {
      return false;
    }
 
    switch($size[2])
    {
       case 1:       //GIF
           $src = imagecreatefromgif($srcFile);
           break;
       case 2:       //JPEG
           $src = imagecreatefromjpeg($srcFile);
           break;
       case 3:       //PNG
           $src = imagecreatefrompng($srcFile);
           break;
       default:
           return false;
           break;
    }
 
    imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
 
    switch($size[2])
    {
       case 1:
       case 2:
           imagejpeg($dest,$destFile, $quality);
           break;
       case 3:
           imagepng($dest,$destFile);
    }
    return $destFile;
 
}
 
sadece html deki form nesnesinin name değeri değiştirsem yetiyormu ?
2008'den beri4.262 mesaj
#5
evet eğer taşımada bir hata yapmadıysam form elementini adı yeterli olacaktır. (Şu anda yazdığım alışveriş sitesinin ürün resim ekleme modülü bu)
yalnız dikkat etmen gerekn birşey daha var GD kütüphanesini kullanıyor. Yüklü olmasına ve aktif olmasına dikkat et
javascript:?? Konuyu açan
2008'den beri165 mesaj
#6
kaberdey dedi: ↑
evet eğer taşımada bir hata yapmadıysam form elementini adı yeterli olacaktır. (şu anda yazdığım alışveriş sitesinin ürün resim ekleme modülü bu)
yalnız dikkat etmen gerekn birşey daha var gd kütüphanesini kullanıyor. Yüklü olmasına ve aktif olmasına dikkat et
yükle.php açilinca boş ekran geliyor hata yok ama boş yüklemiyor dosya??
2008'den beri4.262 mesaj
#7
javascript:?? dedi: ↑
yükle.php açilinca boş ekran geliyor hata yok ama boş yüklemiyor dosya??
şimdi yükledim kopyaladım denedim çalışıyor...
senin başka bir sorunun olduğunu düşünüyorum, Apache ve php için ne kullanıyorsun, ben EasyPHP ile çalıştırdım, kendi hostumda da çalışıyor...

NOT:"yükleme başarılı" onayını ekledim...

dosyalar ekte, bir kez daha deneyebilir misin?...
javascript:?? Konuyu açan
2008'den beri165 mesaj
#8
Kendi yöntemlerimle kendi scriptimi yazdım:) yinede teşekkürler şey bir şey soracaktım
?no=1 açılınca mysql dan resimler tablosundan link sutununun 1.satırındaki veriyi çekmek istiyorum nasıl yaparım yani no=1 olunca 1.satırdaki link değerini çekecek nasıl yaparım yardımcı olursanız sevinirim

Cevabını yaz

Cevap yazmak için giriş yap ya da üye ol. Eski forum kullanıcı adın ve parolanla girebilirsin.