|
 |
|
ผมทำ upload รูปแบบ resite ได้แล้ว แต่ติดตรงนี้นิดหนึ่งช่วยดู code ให้หน่อยนะครับ |
|
 |
|
|
 |
 |
|
คือว่า ผมทำตาม แบบ https://www.thaicreate.com/php/php-upload-resize-insert-to-mysql.html
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>
แล้วก็ upload รูป พร้อยย่อรูปเข้า ฐานข้อมูลเรียบร้อยแล้ว แต่ ติดตรง ที่
1. ถ้า upload รูป เล็ก แล้วมัน จะขยาย ไปด้วยนะครับ อยากได้เฉพาะ รูปที่ใหญ่ เกินที่เรากำหนด เท่านั้นนะครับ
2. คือได้ เฉพาะ jpg อยากให้ ได้ ทั้ง jpg , gif ,png ด้วยนะครับ ต้องเขียนเงื่อนไขแบบไดหรือครับ
3. แบบว่าถ้า upload รูปแล้ว อยากให้ ลบรูปจริงไปเลย ให้ เหลือแต่ รูปที่ resite เท่านั้นนะครับ
ขอความกรุณาด้วยนะครับ
ขอบคุณทุกท่านที่ช่วยตอบนะครับ
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2012-01-07 15:42:24 |
By :
คุณ ณัฐพล |
View :
783 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้ ฟังก์ชั่น Code (PHP)
GetimageSize
ช่วยครับ 
|
 |
 |
 |
 |
Date :
2012-01-07 17:23:17 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
gif ที่เป็นภาพเคลื่อนไหว น่าจะมีปัญหาน่ะครับ 
|
 |
 |
 |
 |
Date :
2012-01-07 17:50:27 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|