ciao,
ho un problema con la gestione delle immagini in una pagina per la modifica di prodotti.
allo stato attuale lo script mi permette di utilizzare solo un immagine per prodotto, mentre io avrei bisogno di poter gestirne almeno 3.
nel form di modifica ho:
Codice PHP:
<?php
if ($pd_thumbnail != '') { // <-- $pd_thumbnail è il nome dell'img estratta dal db con la funzione extact()
?>
[img]<?php echo WEB_ROOT . PRODUCT_IMAGE_DIR . $pd_thumbnail; ?>[/img]<a href="javascript:deleteImage(<?php echo $productId; ?>);">Elimina
Immagine</a>
<?php
}
?>
al submit la variabile viene passata alla funzione modifyProduct() che gestisce l'eliminazione o la sostituzione dell'img.
Codice PHP:
$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');
$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];
if ($mainImage != '') {
_deleteImage($productId);
$mainImage = "'$mainImage'";
$thumbnail = "'$thumbnail'";
} else {
// if we're not updating the image
// make sure the old path remain the same
// in the database
$mainImage = 'pd_image';
$thumbnail = 'pd_thumbnail';
}
$sql = "UPDATE tbl_product
SET cat_id = $catId, pd_name = '$name', pd_cod = '$codice', pd_weight = '$peso', pd_description = '$description',
pd_image = $mainImage, pd_thumbnail = $thumbnail
WHERE pd_id = $productId";
$result = dbQuery($sql);
header('Location: index.php');
}
e la funzione di eliminazione dell'img dalla cartella per le immagini:
Codice PHP:
function _deleteImage($productId)
{
// we will return the status
// whether the image deleted successfully
$deleted = false;
$sql = "SELECT pd_image, pd_thumbnail
FROM tbl_product
WHERE pd_id = $productId";
$result = dbQuery($sql) or die('Cannot delete product image. ' . mysql_error());
if (dbNumRows($result)) {
$row = dbFetchAssoc($result);
extract($row);
if ($pd_image && $pd_thumbnail) {
// remove the image file
$deleted = @unlink(SRV_ROOT . "images/product/$pd_image");
$deleted = @unlink(SRV_ROOT . "images/product/$pd_thumbnail");
}
}
return $deleted;
Pensavo di poter triplicare ( x 3 img ) lo script modifyProduct() tipo 3 query e modificando il nome delle $var ma non funziona.
ho pensato anche di utilizzare uno switch, ma potrebbe funzionare solo se modifico un immagine alla volta, passando in qualche modo una variabile "fittizzia" per far agire lo switch.
ma se modifico più di un immagine alla volta?
insomma non so cosa fare...
suggerimenti?