|
|
|
สอบถามเรื่อง PHP Multiple Upload & Multiple Resize to MySQL หน่อยค่ะ |
|
|
|
|
|
|
|
ดัดแปลงโค้ดมาจาก https://www.thaicreate.com/php/php-multiple-upload-create-thumbnails.html
Code (PHP)
<?
include("config.php");
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
echo "Resize Successful.<br>";
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"../eatatkorat/eat/".$_FILES["fileUpload"]["name"][$i]);
$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,"../eatatkorat/eat/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//*** Insert Record ***//
$strSQL = "INSERT INTO eat_pic ";
$strSQL .="(thumbnails,ResPic) VALUES ('".$new_images."','".$_FILES["fileUpload"]["name"][$i]."')";
$objQuery = mysql_query($strSQL);
}
}
mysql_close($con);
?>
แต่มันบันทึกฐานข้อมูลแค่รูปเดียวเองอ่ะค่ะ
ผิดพลาดตรงไหนหรือค่ะ
ขอบคุณล่วงหน้าค่ะ
Tag : PHP
|
ประวัติการแก้ไข 2012-12-26 16:36:59
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
include("config.php");
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
echo "Resize Successful.<br>";
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$new_images = "Thumbnails_".$_FILES["fileUpload"]["name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"../eatatkorat/eat/".$_FILES["fileUpload"]["name"][$i]);
$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,"../eatatkorat/eat/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//*** Insert Record ***//
$strSQL =" INSERT INTO eat_pic ";
$strSQL.=" (thumbnails, ResPic) ";
$strSQL.=" VALUES ";
$strSQL.=" ('"."Thumbnails_".$_FILES["fileUpload"]["name"][$i]."','".$_FILES["fileUpload"]["name"][$i]."') ";
$objQuery = mysql_query($strSQL) or die (mysql_error());
}
}
mysql_close($con);
?>
|
|
|
|
|
Date :
2012-12-26 16:43:52 |
By :
popnakub |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|