|
 |
|
รบกวนสอบถามเรื่อง การอัพโหลดรูปภาพและการแทนที่รูปภาพครับ |
|
 |
|
|
 |
 |
|
คือผมจะอัพโหลดรูปลงฐานข้อมูลอ่ะครับ เงื่อนไขคือ ถ้า checkid ที่รับมาเป็นค่าว่าง ก็บันทึกลงฐานข้อมูลได้เลยอ่ะครับ
แต่ถ้า checkid ไม่ใช่ค่าว่าง ก็ต้องไปอัพเดตข้อมูลให้ตรงกับ id ที่ checkid รับมาอ่ะครับ
ปัญหาที่ผมเจอคือ พอผมรับค่า checkid มา ข้อมูลไปอัพเดตนะครับ แต่มันไม่ย้ายไฟล์รูปภาพเข้าโฟลเดอร์ temp อ่ะครับ มีแค่ชื่อในฐานข้อมูล รบกวนหน่อยนะครับ
Code (PHP)
if(trim($_FILES["img"]["tmp_name"]) != ""){
if($checkid==""){
$images = $_FILES["img"]["tmp_name"];
srand((double)microtime()*1000000);
$Pic_name=$random_pic = rand(1,9999999);
$new_images = "$Pic_name".".jpg";
copy($_FILES["img"]["tmp_name"],"product/img-product/".$new_images);
$width=80;
$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,"product/img-product/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$strSQL = "INSERT INTO product ";
$strSQL .="(Name_product,Name_team,Size,Number,price,price_cost,img)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["name_product"]."'";
$strSQL .=",'".$_POST["team"]."'";
$strSQL .=",'".$_POST["size"]."'";
$strSQL .=",'".$_POST["number_product"]."'";
$strSQL .=",'".$_POST["price"]."'";
$strSQL .=",'".$_POST["price_cost"]."'";
$strSQL .=",'".$new_images."')";
$objQuery = mysql_query($strSQL);
echo "<script language=\"JavaScript\">";
echo "alert('บันบึกรายการเรียบร้อยแล้ว ค่ะ');";
echo"window.location='index.php';";
echo "</script>";
exit();
}else{
$sql1="Select * from product Where Id_product ='".$_POST["checkid"]."'";
$rstTemp1=mysql_query($sql1);
$rstTempre1=mysql_fetch_array($rstTemp1);
$pic = $rstTempre1["img"];
$delf = unlink("product/img-product/$pic");
$images = $_FILES["img"]["tmp_name"];
srand((double)microtime()*1000000);
$Pic_name=$random_pic = rand(1,9999999);
$new_images = "$Pic_name".".jpg";
copy($_FILES["img"]["tmp_name"],"product/img-product/".$new_images);
$width=80;
$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,"product/img-product/".$new_images);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$strSQL=" UPDATE product SET Name_product = '".$_POST["name_product"]."',Name_team = '".$_POST["team"]."',Size = '".$_POST["size"]."',Number = '".$_POST["number_product"]."',price = '".$_POST["price"]."',price_cost = '".$_POST["price_cost"]."',img = '".$new_images."' WHERE Id_product = '".$checkid."' " ;
echo "<script language=\"JavaScript\">";
echo "alert('update รายการเรียบร้อยแล้ว ค่ะ');";
echo"window.location='index.php';";
echo "</script>";
exit();
}
}
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2014-10-08 13:42:48 |
By :
lungzee |
View :
721 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มี Error ไหม๊ครับ ปกติถ้า Resize แล้วไม่ได้ก็น่าจะ Error น่ะครับ
|
 |
 |
 |
 |
Date :
2014-10-08 16:45:55 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมวาง ผิดตำแหน่งเองอ่าครับ เหมือนใช้ if else งงอ่าครับ โค๊ดเลยทำตามลำดับไม่ถูกครับ
|
 |
 |
 |
 |
Date :
2014-10-09 14:17:33 |
By :
lungzee |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|