Salve a tutti!
ho un e-commerce che mi da problemi con l'upload di immagini, sia quando creo una galleria che quando creo un nuovo prodotto, riesce ad inserire tutti i dati nel database tranne il nome della foto e la foto nella cartella di destinazione, ecco il codice:
Codice PHP:
function addCategory()
{
$name = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$image = $_FILES['fleImage'];
$parentId = $_POST['hidParentId'];
$catImage = uploadImage('fleImage', SRV_ROOT . '/images/category/');
$sql = "INSERT INTO tbl_category (cat_parent_id, cat_name, cat_description, cat_image)
VALUES ($parentId, '$name', '$description', '$catImage')";
$result = dbQuery($sql) or die('Cannot add category' . mysql_error());
header('Location: index.php?catId=' . $parentId);
}
/*
Upload an image and return the uploaded image name
*/
function uploadImage($inputName, $uploadDir)
{
$image = $_FILES[$inputName];
$imagePath = '';
// if a file is given
if (trim($image['tmp_name']) != '') {
// get the image extension
$ext = substr(strrchr($image['name'], "."), 1);
// generate a random new file name to avoid name conflict
$imagePath = md5(rand() * time()) . ".$ext";
// check the image width. if it exceed the maximum
// width we must resize it
$size = getimagesize($image['tmp_name']);
if ($size[0] > MAX_CATEGORY_IMAGE_WIDTH) {
$imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_CATEGORY_IMAGE_WIDTH);
} else {
// move the image to category image directory
// if fail set $imagePath to empty string
if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) {
$imagePath = '';
}
}
}
return $imagePath;
}
Cosa sbaglio? ho controllato tutto ma niente. (almeno penso)