Hi frnds...

here i am confusing a lot..lot...from last 4 days i am struggling here...plz solve this problem aeap with patience....


This is my code for uploading images to my folder and db table...now, all images are blur at my user side...so, i need to create THUMBNAIL images for every image...plz change my code and write code for thumbmail creation..explain it breifly....

<?php
ob_start();
session_start();
include("config.inc.php");
$gcategory=mysql_real_escape_string($_POST['gcategory']);

$gname=mysql_real_escape_string($_POST['gname']);

$date=date('y-m-d');

foreach ($_FILES["attachments4"]["tmp_name"] as $key => $error) 
{
    if ($error == UPLOAD_ERR_OK) 
{

		@$tmp_name0 = $_FILES["attachments4"]["tmp_name"][0];
        @$name0 = $_FILES["attachments4"]["name"][0];
		
		@$tmp_name1 = $_FILES["attachments4"]["tmp_name"][1];
        @$name1 = $_FILES["attachments4"]["name"][1];
		@$tmp_name2 = $_FILES["attachments4"]["tmp_name"][2];
        @$name2 = $_FILES["attachments4"]["name"][2];
		@$tmp_name3 = $_FILES["attachments4"]["tmp_name"][3];
        @$name3 = $_FILES["attachments4"]["name"][3];
		@$tmp_name4 = $_FILES["attachments4"]["tmp_name"][4];
        @$name4 = $_FILES["attachments4"]["name"][4];
		
		@$tmp_name5 = $_FILES["attachments4"]["tmp_name"][5];
        @$name5 = $_FILES["attachments4"]["name"][5];
		@$tmp_name6 = $_FILES["attachments4"]["tmp_name"][6];
        @$name6 = $_FILES["attachments4"]["name"][6];
		@$tmp_name7 = $_FILES["attachments4"]["tmp_name"][7];
        @$name7 = $_FILES["attachments4"]["name"][7];
		
		@$tmp_name8 = $_FILES["attachments4"]["tmp_name"][8];
        @$name8 = $_FILES["attachments4"]["name"][8];
		@$tmp_name9 = $_FILES["attachments4"]["tmp_name"][9];
        @$name9 = $_FILES["attachments4"]["name"][9];

		$title1="../../gallery/allgallerys/$gcategory/$gname";
		
		@move_uploaded_file($tmp_name0, "$title1"."/"."$name0");
	    @move_uploaded_file($tmp_name1, "$title1"."/"."$name1");
		@move_uploaded_file($tmp_name2, "$title1"."/"."$name2");
		@move_uploaded_file($tmp_name3, "$title1"."/"."$name3");
		@move_uploaded_file($tmp_name4, "$title1"."/"."$name4");
	    @move_uploaded_file($tmp_name5, "$title1"."/"."$name5");
		@move_uploaded_file($tmp_name6, "$title1"."/"."$name6");
		@move_uploaded_file($tmp_name7, "$title1"."/"."$name7");
		@move_uploaded_file($tmp_name8, "$title1"."/"."$name8");
		@move_uploaded_file($tmp_name9, "$title1"."/"."$name9");
		}
		}
		

	
$sql="select id from gallerymain where gcategory='$gcategory' and gname='$gname'";
$res=mysql_query($sql)or die(mysql_error());
while($row=mysql_fetch_array($res)){
$gid=$row['id'];
}
$title="allgallerys/$gcategory/$gname";

if($name0!='')
{	
$path="$title"."/"."$name0";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name1!='')
{	
$path="$title"."/"."$name1";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name2!='')
{	
$path="$title"."/"."$name2";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name3!='')
{	
$path="$title"."/"."$name3";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name4!='')
{	
$path="$title"."/"."$name4";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name5!='')
{	
$path="$title"."/"."$name5";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name6!='')
{	
$path="$title"."/"."$name6";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name7!='')
{	
$path="$title"."/"."$name7";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}

if($name8!='')
{	
$path="$title"."/"."$name8";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}
if($name9!='')
{	
$path="$title"."/"."$name9";
$sql="insert into galleryphotos values('','$gid','$path','$date')";
mysql_query($sql)or die(mysql_error());
}
//header('Location : uploadgallery.php'); 
?>

Thanks in advance....

This function should do the trick as long as you have the PHP GD libraries.
Pass two file paths and it will copy $srcim into $destim and resize it to the size of $size.
For more details see this as that is where I got most of the code.

<?php
function makeThumbnail($srcim, $destim) {
$size = 200;
$thumb = ImageCreate(200, 200); 

$draw_from = $srcim;
$dim = GetImageSize($draw_from);
if($dim[0]>$dim[1])
{
$to_w = $size;
$to_h = round($dim[1]*($size/$dim[0]));
$to_x = 0;
$to_y = round($size-$to_h)/2;
}
else
{
$to_h = $size;
$to_w = round($dim[0]*($size/$dim[1]));
$to_y = 0;
$to_x = round($size-$to_w)/2;
}
if($dim[2]==1) {$from = ImageCreateFromGIF($draw_from);}
elseif($dim[2]==2) {$from = ImageCreateFromJPEG($draw_from);}
elseif($dim[2]==3) {$from = ImageCreateFromPNG($draw_from);} 
ImageCopyResized($thumb, $from, $to_x, $to_y, 0,  
0, $to_w, $to_h, $dim[0], $dim[1]); 
switch($dim[2]){
case 1:
ImageGIF($thumb, $destim);
break;		
case 2:
ImageJPEG($thumb, $destim);
break;
case 3:
ImagePNG($thumb, $destim);
break;
}
ImageDestroy($from);
ImageDestroy($thumb); 
return;
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.