|
|
|
PHP Resize Thumbnails Image and Update to MySQL ทำยังไงครับช่วยสอนทีครับ |
|
|
|
|
|
|
|
Code ก็มีให้น่ะครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP Upload Resize to MySQL</title>
</head>
<body>
<?
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["name"]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$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,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"]."')";
$objQuery = mysql_query($strSQL);
}
?>
<a href="phpUploadResizeToMySQL3.php">View files</a>
</body>
</html>
Go to : PHP Resize Thumbnails Image and Insert to MySQL
|
|
|
|
|
Date :
2011-12-08 06:11:08 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมอยาก จะ Update ลง mysql อ่ะครับ
|
|
|
|
|
Date :
2011-12-08 21:33:25 |
By :
samugla |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
//echo $_POST["txtdetail"];
//$Code=$_GET["codes"];
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<?
$MyConnect=mysql_connect("localhost","root","root") or die("ไม่สมารถติดต่อได้");
$objDB = mysql_select_db("mydb");
if(trim($_FILES["fileUpload"]["tmp_name"]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"];
copy($_FILES["fileUpload"]["tmp_name"],"MyResize/".$_FILES["fileUpload"]["name"]);
$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round($width*$size[1]/$size[0]);
$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,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//resize รูป
}
$strSQL = "UPDATE query SET ";
$strSQL .="q_name='".$_POST["txtname"]."' ";
$strSQL .=",q_email='".$_POST["txtemail"]."' ";
$strSQL .=",q_subject='".$_POST["txtsubject"]."' ";
$strSQL .=",q_detail='".$_POST["txtdetail"]."' ";
$strSQL .=",create_date='".$_POST["txtdate"]." ' ";
//$strSQL .=" ,q_pic = '".$_POST[" $new_images"]. " ' WHERE q_id = '".$_GET["codes"]."' ";
//$objQuery = mysql_query($strSQL);
$strSQL .=" ,q_pic = '".$_FILES["fileUpload"]["name"]. " ' WHERE q_id = '".$_GET["codes"]."' ";
//ถ้าต้องการส่งค่า $new_images ใส่ไปใน q_pic ต้องทำอย่างไร-------------------------------------------------------------
//$strSQL.="WHERE q_id='".$_GET["codes"]."'";
//echo $strSQL;
//$strSQL = "UPDATE query ";
//$strSQL .=" SET q_pic = '".$_FILES["fileUpload"]["$new_images"]."' WHERE q_id = '".$_GET["codes"]."' ";
$objQuery=mysql_query($strSQL);
if($objQuery)
{
echo "SAVE ";
}
else
{
echo "error save[".$strSQL."]";
}
mysql_close( $MyConnect);
?>
<a href="editefrom.php?codes=<?=$_GET["codes"];?>">แก้ไข</a> | แสดงผล
</body>
</html>
|
|
|
|
|
Date :
2011-12-08 21:53:45 |
By :
samugla |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ก็เอารูป มาย่อแล้วทำการบันทึกเป็นไฟล์
จากนั้นก็ทำการ update เข้า mysql ตามปกติ (blob)
|
|
|
|
|
Date :
2011-12-09 01:17:35 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สะดวกไหม ครับ ขอดูตัวอย่างหน่อยอยาก จะ เอา $new_images ใส่ ในq_pic อ่ะครับ
|
|
|
|
|
Date :
2011-12-09 15:07:32 |
By :
samugla |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|