<?
// upload.inc.php
// by EJDER (www.ejder.com.tr)
class upload
{
var $directory_name;
var $max_filesize;
var $error;
var $user_tmp_name;
var $user_file_name;
var $user_file_size;
var $user_file_type;
var $user_full_name;
var $thumb_name;
function set_directory($dir_name = ".")
{
$this->directory_name = $dir_name;
}
function set_max_size($max_file = 300000)
{
$this->max_filesize = $max_file;
}
function error()
{
return $this->error;
}
function is_ok()
{
if(isset($this->error))
return FALSE;
else
return TRUE;
}
function set_tmp_name($temp_name)
{
$this->user_tmp_name = $temp_name;
}
function set_file_size($file_size)
{
$this->user_file_size = $file_size;
}
function set_file_type($file_type)
{
$this->user_file_type = $file_type;
}
function set_file_name($file)
{
$this->user_file_name = $file;
$this->user_full_name = $this->directory_name."/".$this->user_file_name;
}
function resize($max_width = 0, $max_height = 0 )
{
if(eregi("\.png$",$this->user_full_name))
{
$img = ImageCreateFromPNG ($this->user_full_name);
}
if(eregi("\.(jpg|jpeg)$",$this->user_full_name))
{
$img = ImageCreateFromJPEG ($this->user_full_name);
}
if(eregi("\.gif$",$this->user_full_name))
{
$img = ImageCreateFromGif ($this->user_full_name);
}
$FullImage_width = imagesx ($img);
$FullImage_height = imagesy ($img);
if(isset($max_width) && isset($max_height) && $max_width != 0 && $max_height != 0)
{
$new_width = $max_width;
$new_height = $max_height;
}
else if(isset($max_width) && $max_width != 0)
{
$new_width = $max_width;
$new_height = ((int)($new_width * $FullImage_height) / $FullImage_width);
}
else if(isset($max_height) && $max_height != 0)
{
$new_height = $max_height;
$new_width = ((int)($new_height * $FullImage_width) / $FullImage_height);
}
else
{
$new_height = $FullImage_height;
$new_width = $FullImage_width;
}
/*
$ratio = ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
$new_width = ((int)($FullImage_width * $ratio)); //full size width
$new_height = ((int)($FullImage_height * $ratio)); //full size height
$ratio = ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
$new_width = ((int)($new_width * $ratio)); //mid size width
$new_height = ((int)($new_height * $ratio)); //mid size height
*/
$full_id = ImageCreateTrueColor ( $new_width , $new_height );
ImageCopyResampled ( $full_id, $img, 0,0,0,0, $new_width, $new_height, $FullImage_width, $FullImage_height );
if(eregi("\.(jpg|jpeg)$",$this->user_full_name))
{
$full = ImageJPEG( $full_id, $this->user_full_name,100);
}
if(eregi("\.png$",$this->user_full_name))
{
$full = ImagePNG( $full_id, $this->user_full_name);
}
if(eregi("\.gif$",$this->user_full_name))
{
$full = ImageGIF($full_id, $this->user_full_name);
}
ImageDestroy( $full_id );
unset($max_width);
unset($max_height);
}
function start_copy()
{
if(!isset($this->user_file_name))
$this->error = "You must define filename!";
if ($this->user_file_size <= 0)
$this->error = "File size error (0): $this->user_file_size KB<br>";
if ($this->user_file_size > $this->max_filesize)
$this->error = "File size error (1): $this->user_file_size KB<br>";
if (!isset($this->error))
{
$filename = basename($this->user_file_name);
if (!empty($this->directory_name))
$destination = $this->user_full_name;
else
$destination = $filename;
/* file exists control.. if file is exists it upload new file name
if (file_exists($destination))
{
srand((double)microtime()*1000000);
$filename = rand(0,20000)."_".$filename;
if (!empty ($this->directory_name) )
$destination = $this->directory_name."/".$filename;
else
$destination = $filename;
}
*/
if(!is_uploaded_file($this->user_tmp_name))
$this->error = "File ".$this->user_tmp_name." is not uploaded correctly.";
if (!@move_uploaded_file ($this->user_tmp_name,$destination))
$this->error = "Impossible to copy ".$this->user_file_name." from $userfile to destination directory.";
}
}
function set_thumbnail_name($thumbname)
{
if(eregi("\.png$",$this->user_full_name))
$this->thumb_name = $this->directory_name."/".$thumbname.".png";
if(eregi("\.(jpg|jpeg)$",$this->user_full_name))
$this->thumb_name = $this->directory_name."/".$thumbname.".jpg";
if(eregi("\.gif$",$this->user_full_name))
$this->thumb_name = $this->directory_name."/".$thumbname.".gif";
}
function create_thumbnail()
{
if (!copy($this->user_full_name, $this->thumb_name))
{
echo "<br>".$this->user_full_name.", ".$this->thumb_name."<br>";
echo "failed to copy $file...<br />\n";
}
}
function set_thumbnail_size($max_width = 0, $max_height = 0 )
{
if(eregi("\.png$",$this->thumb_name))
{
$img = ImageCreateFromPNG ($this->thumb_name);
}
if(eregi("\.(jpg|jpeg)$",$this->thumb_name))
{
$img = ImageCreateFromJPEG ($this->thumb_name);
}
if(eregi("\.gif$",$this->thumb_name))
{
$img = ImageCreateFromGif ($this->thumb_name);
}
$FullImage_width = imagesx ($img);
$FullImage_height = imagesy ($img);
if(isset($max_width) && isset($max_height) && $max_width != 0 && $max_height != 0)
{
$new_width = $max_width;
$new_height = $max_height;
}
else if(isset($max_width) && $max_width != 0)
{
$new_width = $max_width;
$new_height = ((int)($new_width * $FullImage_height) / $FullImage_width);
}
else if(isset($max_height) && $max_height != 0)
{
$new_height = $max_height;
$new_width = ((int)($new_height * $FullImage_width) / $FullImage_height);
}
else
{
$new_height = $FullImage_height;
$new_width = $FullImage_width;
}
/*
$ratio = ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
$new_width = ((int)($FullImage_width * $ratio)); //full size width
$new_height = ((int)($FullImage_height * $ratio)); //full size height
$ratio = ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
$new_width = ((int)($new_width * $ratio)); //mid size width
$new_height = ((int)($new_height * $ratio)); //mid size height
*/
$full_id = ImageCreateTrueColor ( $new_width , $new_height );
ImageCopyResampled ( $full_id, $img, 0,0,0,0, $new_width, $new_height, $FullImage_width, $FullImage_height );
if(eregi("\.(jpg|jpeg)$",$this->thumb_name))
{
$full = ImageJPEG( $full_id, $this->thumb_name,100);
}
if(eregi("\.png$",$this->thumb_name))
{
$full = ImagePNG( $full_id, $this->thumb_name);
}
if(eregi("\.gif$",$this->thumb_name))
{
$full = ImageGIF($full_id, $this->thumb_name);
}
ImageDestroy( $full_id );
unset($max_width);
unset($max_height);
}
}
?> -ücretsiz* upload class
27
●2.773
- 24-01-2007, 13:27:39Resimlerinizi ve dosyalarınızı yükleyebilirsiniz. Yüklediğiniz resimlerin boyutlarını değiştirerek ufak hallerini oluşturabilirsiniz.
- 24-01-2007, 13:35:37Örnek
Deneme.html
<html> <head> <title>Upload</title> </head> <body> <center> <h2>Upload</h2> <form name="upload" action="upload.php" method="post" enctype="multipart/form-data"> Choose File: <input type="file" name="file"> <br><br> <input type="submit" name="upload" value="Send"> </form> </center> </body> </html><? // upload.php // by EJDER (www.ejder.com.tr) include "upload.inc.php"; // Defining Class // Sınıfı Tanımlıyoruz $yukle = new upload; // Set Max Size // Yüklenecek en büyük dosya boyutunu ayarlıyoruz $yukle->set_max_size(180000); // Set Directory // Yüklenecek dizini ayarlıyoruz, bu dizin 0666 veya 0777 CHMOD ile ayarlanmalı $yukle->set_directory("data"); // Do not change // Set Temp Name for upload, $_FILES['file']['tmp_name'] is automaticly get the temp name // Değiştirmeyin // Geçici yükleme dosyasını ayarlar, $_FILES['file']['tmp_name'] otomatik olarak bu ismi alır $yukle->set_tmp_name($_FILES['file']['tmp_name']); // Do not change // Set file size, $_FILES['file']['size'] is automaticly get the size // Değiştirmeyin // Dosya boyutunu ayarlayın, $_FILES['file']['size'] otomatik olarak dosya boyutunu alır $yukle->set_file_size($_FILES['file']['size']); // Do not change // Set File Type, $_FILES['file']['type'] is automaticly get the type // Değiştirmeyin // Dosya tipini ayarlayın, $_FILES['file']['type'] otomatik olarak dosya tipini alır $yukle->set_file_type($_FILES['file']['type']); // Set File Name, $_FILES['file']['name'] is automaticly get the file name.. you can change // Dosya adını ayarla, $_FILES['file']['name'] otomatik olarak dosyanın ismini alır, istediğiniz başka bir isim verebilirsiniz $yukle->set_file_name($_FILES['file']['name']); // Start Copy Process // Kopyalama işlemini başlat $yukle->start_copy(); // If uploaded file is image, you can resize the image width and height // Support gif, jpg, png // Eğer yüklenen dosya resim ise boyutunu ayarlayabilirsiniz.. // Gif, jpg ve png desteklidir // genişlik, yükseklik şeklindedir, sadece birini yazar diğerine 0 yazarsanız otomatik olarak onu ayarlar $yukle->resize(0,0); // Control File is uploaded or not // If there is error write the error message // Yüklenen dosyayı kontrol et, eğer hata varsa hata mesajını yaz if($yukle->is_ok()) echo "Yüklendi"; else echo $yukle->error()."<br>"; // Set a thumbnail name // Kopyasının adını ayarla $yukle->set_thumbnail_name("hatice"); // create thumbnail // Kopya oluştur $yukle->create_thumbnail(); // change thumbnail size // Kopyanın boyutunu değiştir $yukle->set_thumbnail_size(0, 250); $yukle->set_thumbnail_name("hatice2"); $yukle->create_thumbnail(); $yukle->set_thumbnail_size(50, 0); $yukle->set_thumbnail_name("hatice3"); $yukle->create_thumbnail(); $yukle->set_thumbnail_size(62, 150); ?>