มีปัญหาเรื่องuploaded_file ครับ ตรง move_uploaded_file() บน Web server ไม่ได้ แต่! กับใช้ บน AppServ ได้
Code
error : Warning: move_uploaded_file(/home/comzacom4/domains/comza.com/public_html/images/product/fc72d3b670f638d10243ec488b657e6e.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/comzacom4/domains/comza.com/public_html/admin/product/processProduct.php on line 79
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpd0A9iD' to '/home/comzacom4/domains/comza.com/public_html/images/product/fc72d3b670f638d10243ec488b657e6e.jpg' in /home/comzacom4/domains/comza.com/public_html/admin/product/processProduct.php on line 79
Warning: Cannot modify header information - headers already sent by (output started at /home/comzacom4/domains/comza.com/public_html/admin/product/processProduct.php:79) in /home/comzacom4/domains/comza.com/public_html/admin/product/processProduct.php on line 144
Code
/*
Upload an image and return the uploaded image name
*/
function uploadProductImage($inputName, $uploadDir)
{
$image = $_FILES[$inputName];
$imagePath = '';
$thumbnailPath = '';
ผิดตรงไหน จะต้องทำยังไง ครับ ขอบคุณครับ
if (trim($image['tmp_name']) != '') {
$ext = substr(strrchr($image['name'], "."), 1); /
$imagePath = md5(rand() * time()) . ".$ext";
list($width, $height, $type, $attr) = getimagesize($image['tmp_name']);
if (LIMIT_PRODUCT_WIDTH && $width > MAX_PRODUCT_IMAGE_WIDTH) {
$result = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_PRODUCT_IMAGE_WIDTH);
$imagePath = $result;
} else {
line 79 >> $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
}
if ($result) {
$thumbnailPath = md5(rand() * time()) . ".$ext";
$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
if (!$result) {
unlink($uploadDir . $imagePath);
$imagePath = $thumbnailPath = '';
} else {
$thumbnailPath = $result;
}
} else {
$imagePath = $thumbnailPath = '';
}
}
return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}
/*
Modify a product
*/
function modifyProduct()
{
$productId = (int)$_GET['productId'];
$catId = $_POST['cboCategory'];
$name = $_POST['txtName'];
$description = $_POST['mtxDescription'];
line 144 >> $price = str_replace(',', '', $_POST['txtPrice']);
$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');
$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];
if ($mainImage != '') {
_deleteImage($productId);
$mainImage = "'$mainImage'";
$thumbnail = "'$thumbnail'";
} else {
$mainImage = 'pd_image';
$thumbnail = 'pd_thumbnail';
}
$sql = "UPDATE tbl_product
SET cat_id = $catId, pd_name = '$name', pd_description = '$description', pd_price = $price,
pd_image = $mainImage, pd_thumbnail = $thumbnail
WHERE pd_id = $productId";
$result = dbQuery($sql);
header('Location: index.php');
}
/*
Remove a product
*/
Tag : PHP, MySQL, CakePHP