|
|
|
PHP Resize Thumbnails Image and Insert to MySQL เป็นการ Upload ไฟล์และทำการ Resize รูปภาพ |
|
|
|
|
|
|
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP Upload Resize to MySQL</title>
</head>
<body>
<form name="form1" method="post" action="phpUploadResizeToMySQL2.php" enctype="multipart/form-data">
<input type="file" name="fileUpload"><br>
<input name="btnSubmit" type="submit" value="Submit">
</form>
</body>
</html>
===================
<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>
==========================
พอถึงตรง $strSQL = "INSERT INTO files ";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"]."')";
เมื่อมีข้อมูลรูปภาพแล้ว อยากจะupdate รูปภาพใหม่เลยเขียนเป็น
$strSQL = "UPDATE files SET";
$strSQL .="(Thumbnails,FilesName) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"]."')
where id ='$id' ";
อยากรู้คับ ว่าเป็นเพราะอะไร
Tag : PHP
|
|
|
|
|
|
Date :
2010-12-17 21:29:19 |
By :
น้องใหม่ |
View :
1168 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|