|
|
|
ช่วยดูโค้ดการแทรกรูปภาพเป็น resize และกำหนดขนาดไม่เกิน 500 kb |
|
|
|
|
|
|
|
เราจะแทรกโค้ด กำหนดว่า อัพโหลดรูปไม่เกิน 500 k ตรงไหนครับ โดยใช้คำสั่งอะไร
Code (PHP)
<?
$date = date('YmdHis');
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
{
if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")
{
$images = $_FILES["fileUpload"]["tmp_name"][$i];
$new_images = "Thumbnails_".$date.$_FILES["fileUpload"]["name"][$i];
copy($_FILES["fileUpload"]["tmp_name"][$i],"MyResize/".$date.$_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,"MyResize/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
echo "Resize Successful.<br>";
//*** Insert Record ***//
$objConnect = mysql_connect("localhost","root","@9174") or die("Error Connect to Database");
$objDB = mysql_select_db("networkpic");
$strSQL = "INSERT INTO files_all";
//$strSQL .="(Thumbnails,FilesName) VALUES ('".$_POST["Fil'".$new_images."','".$date.$_FILES["fileUpload"]["name"][$i]."')";
$strSQL .="(FilesID,Thumbnails,FilesName_all) VALUES ('".$_POST["FilesID"]."','".$new_images."','".$date.$_FILES["fileUpload"]["name"][$i]."')";
$objQuery = mysql_query($strSQL);
}
}
Tag : PHP
|
|
|
|
|
|
Date :
2013-05-11 10:35:04 |
By :
faksit |
View :
859 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$_FILES["fileUpload"]["size"]
|
|
|
|
|
Date :
2013-05-11 15:31:28 |
By :
teez1232002 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|