bu fonksiyon benim değil ama ihtiyaçlarıma göre düzenledim 
aynı kalsör içine resmin başına small_ ekleyerek kaydediyor.
PHP Kodu:
function resize_img( $Dir, $Image, $MaxWidth = 120, $MaxHeight = 120 )
{
list($ImageWidth,$ImageHeight,$TypeCode)=getimagesize($Dir.$Image);
$Quality = 100;
$NewDir = $Dir;
$NewImage = "small_".$Image;
$ImageType=($TypeCode==1?"gif":($TypeCode==2?"jpeg":
($TypeCode==3?"png":FALSE)));
$CreateFunction="imagecreatefrom".$ImageType;
$OutputFunction="image".$ImageType;
if ( $ImageType )
{
$Ratio=($ImageHeight/$ImageWidth);
$ImageSource=$CreateFunction($Dir.$Image);
if ($ImageWidth > $MaxWidth || $ImageHeight > $MaxHeight)
{
if ($ImageWidth > $MaxWidth)
{
$ResizedWidth=$MaxWidth;
$ResizedHeight=$ResizedWidth*$Ratio;
}
else
{
$ResizedWidth=$ImageWidth;
$ResizedHeight=$ImageHeight;
}
if ($ResizedHeight > $MaxHeight)
{
$ResizedHeight=$MaxHeight;
$ResizedWidth=$ResizedHeight/$Ratio;
}
$ResizedImage=imagecreatetruecolor($ResizedWidth,$ResizedHeight);
imagecopyresampled($ResizedImage,$ImageSource,0,0,0,0,$ResizedWidth,
$ResizedHeight,$ImageWidth,$ImageHeight);
}
else
{
$ResizedWidth=$ImageWidth;
$ResizedHeight=$ImageHeight;
$ResizedImage=$ImageSource;
}
$OutputFunction($ResizedImage,$NewDir.$NewImage,$Quality);
return true;
}
else
return false;
}
burdan itibaren ben yazdım hata olabilir 
PHP Kodu:
if( is_uploaded_file( $_FILES['product_img']['tmp_name'] ) ) //gonderilen dosya temp kalsorüne taşınmış mı?
{
$img_data = getimagesize( $_FILES['product_img']['tmp_name'] ); //resim datalarını oku
if( $img_data['2'] != 1 || $img_data['2'] != 2 ) //1= gif 2 = jpg
{ ///dosya beklediğimiz formatta mı kontrol et
$source = $_FILES['product_img']['tmp_name'];
//hedef dosya adı kullanılıyor olabilir
//ona göre kullanılmayan bir isim yarat
$dest1 = generateUniqeNameForProductImage( $_FILES['product_img']['name'] );
$dest = "../product_img/".$dest1;
if( !move_uploaded_file( $source, $dest ) )
{
$err .= "Dosya upload hatası KOD :1 <br />";
}
else //resim büyükse küçüğünü oluştur
{
if( $img_data['0'] > 150 && $img_data['1'] > 150 )
{
resize_img( "../product_img/",$dest1 );
}
}
}
else
{
$err .= "Sadece .jpg ve .gif formatlý resimleri upload edebilirsiniz. <br />";
}
}
else
{
$err .= "Dosya upload hatasý KOD :3 <br />";
}
product_img formdaki
<input type="file" name="product_img">
resmi upload ederken kullanılan diğer fonksiyonlar
PHP Kodu:
function generateUniqeNameForProductImage( $filename )
{
return generateUniqeFileName( "../product_img/", $filename );
}
PHP Kodu:
function generateUniqeFileName( $dir, $filename )
{
$new_filename = $filename;
do
{
if( file_exists( $dir.$new_filename ) )
{
$clk = true;
$alfabe="abcdefghijkmnpqrstuvwxyz23456789";
$temp = substr(str_shuffle($alfabe),0,9);
$new_filename = $temp.$filename;
}
else
{
$clk = false;
}
}while( $clk );
return $new_filename;
}
Bookmarks