<?php
session_start();
include './connection.php';
include './check_admin.php';
include './functions.php';
check_admin();
$myp = $_POST['p'];
if (!empty($myp['product_name']) && !empty($myp['product_detail']) && !empty($myp['product_price'])) {
$ext = findexts($_FILES['fileUpload']['name']);
$target = "product_img/";
$target = $target . time() . $ext;
//if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)
if (trim($_FILES["fileUpload"]["tmp_name"]) != "") {
$images = $_FILES["fileUpload"]["tmp_name"];
//$new_images = "Thumbnails_".$_FILES["uploaded"]["name"];
copy($_FILES["fileUpload"]["tmp_name"], $target);
$width = 400; //*** 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, $target);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
$sql = "INSERT INTO products(
category_id,
product_name,
product_detail,
product_img,
product_price,
created)
VALUES(
'" . $myp['category_id'] . "',
'" . $myp['product_name'] . "',
'" . $myp['product_detail'] . "',
'" . $target . "',
'" . $myp['product_price'] . "',
'" . date("Y-m-d H:i:s") . "')";
if (mysql_query($sql)) {
echo "Success: เพิ่มข้อมูลสินค้าเรียบร้อย
<a href='products_all.php'>รายการสินค้า</a>";
} else {
echo "Eror: เพิ่มข้อมูลสินค้าไม่ได้
<a href='products_all.php'>รายการสินค้า</a>";
}
} else {
echo "Eror: Upload รูปไม่ได้
<a href='products_all.php'>รายการสินค้า</a>";
}
} else {
echo "Error: กรอกข้อมูลไม่ครบ
<a href='products_all.php'>รายการสินค้า</a>";
}
ตอบ/อธิบาย