ช่วยบอกวิธีการนำรูปที่ Resize ไปเก็บยังฐานข้อมูลทีครับ
<html>
<head>
<title>Upload รูปภาพด้วยการ Resize</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>
<body>
<?
if($file=="")
{
?>
<form name="form1" enctype="multipart/form-data" method="post" action="">
เลือกรูปภาพ
<input type="file" name="file">
<input type="submit" name="Submit" value="Upload">
</form>
<?
}
else
{
$images = $file;
//กำหนดความสูงของรูปใหม่
$height=110;
$size=GetimageSize($images);
$width=round($height*$size[0]/$size[1]);
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
ImageJPEG($images_fin,$file_name);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Uploads รูปสำเร็จแล้วครับ<br>";
echo "<br><img src=\"$file_name\">";
}
?>
</body>
</html>
ขอบคุณครับ Tag : - - - -
Date :
12 ธ.ค. 2550 01:08:18
By :
veev
View :
1412
Reply :
3
<?
$photo=$_FILES['photo']['tmp_name'];
$phot_name=$_FILES['photo']['name'];
$phot_size=$_FILES['photo']['size'];
$phot_type=$_FILES['photo']['type'];
$detail=$_POST['detail'];
$id_title=$_POST[id_title];
echo $id_title;
if(!$photo)
{
echo"<h3>Error:ไม่สามารถ upload รูปภาพได้</h3>";
exit();
}
$ext = strtolower(end(explode('.',$photo_name)));
if($ext =="jpg" or $ext == "jpeg" or $ext =="png" or $ext == "gif")
{
include ("../connect.php");
$sql="insert into tb_photo values(null,'','$detail','$id_title')";
mysql_query($sql,$conn);
$sql="select max(id_photo) from tb_photo";
$result=mysql_query($sql,$conn);
$r=mysql_fetch_array($result);
$id_max=$r[0];
$filename=$id_max.".".$ext;
copy($photo,"../gallery/images_large/$filename");
if($ext == "jpg" or $ext=="jpeg")
{
$ori_img = imagecreatefromjpeg($photo);
}
elseif ($ext =="png")
{
$ori_img = imagecreatefrompng($photo);
}
elseif ($ext =="gif")
{
$ori_img = imagecreatefromgif($photo);
}
$ori_size = getimagesize($photo);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
if($ori_w >= $ori_h)
{
$new_w = 100;
$new_h = round(($new_w/$ori_w) * $ori_h);
}
else
{
$new_h = 100;
$new_w = round (($new_h/$ori_h) * $ori_w);
}
$new_img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($new_img,$ori_img,0,0,0,0,$new_w,$new_h,$ori_w,$ori_h);
if ($ext == "jpg" or $ext == "jpeg")
{
imagejpeg($new_img,"../gallery/images_small/$filename");
}
elseif ($ext == "png")
{
imagepng($new_img,"../gallery/images_small/$filename");
}
elseif ($ext == "gif")
{
imagegif($new_img,"../gallery/images_small/$filename");
}
imagedestroy($ori_img);
imagedestroy($new_img);
$sql = "update tb_photo set name_photo='$filename' where id_photo ='$id_max'";
mysql_query($sql,$conn);
echo "<h3>Upload รูปภาพเรียบร้อยแล้ว</h3>";
echo "<a href='admin_photo.php?id_title=$id_title'>กลับหน้าหลัก</a>";
}
else
{
echo"<h3>Error: ไม่สามารถ upload รูปภาพได้</h3>";
}
?>
Date :
12 ธ.ค. 2550 01:26:40
By :
namfar
ใน table มีฟิวอะไรบ้างครับ
Date :
12 ธ.ค. 2550 02:27:32
By :
veev
ดูแล้วไม่เข้าใจครับจากตัวอย่างมีมากกว่า 1 ตารางหรอครับ
Date :
12 ธ.ค. 2550 02:30:58
By :
veev
Load balance : Server 02