fix: percorso immagine in pagina gestione prodotti gestito incorrettamente

This commit is contained in:
2026-04-10 13:47:54 +02:00
parent 83adb359f8
commit 72c8872c39
+7 -5
View File
@@ -33,15 +33,16 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save'])) {
$stock = $_POST['stock']; $stock = $_POST['stock'];
// Gestione immagine // Gestione immagine
$image_path = $_POST['current_image']; $image_path = basename($_POST['current_image']);
if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
$target_dir = "../img/"; $target_dir = "../img/";
$target_file = $target_dir . basename($_FILES["image"]["name"]); $image_name = basename($_FILES["image"]["name"]);
$target_file = $target_dir . $image_name;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
// Controlli base // Controlli base
if (in_array($imageFileType, ['jpg', 'png', 'jpeg', 'gif'])) { if (in_array($imageFileType, ['jpg', 'png', 'jpeg', 'gif'])) {
if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
$image_path = "/img/" . basename($_FILES["image"]["name"]); $image_path = $image_name;
} }
} }
} }
@@ -161,9 +162,10 @@ $stmt_prod->close();
</div> </div>
</td> </td>
<td> <td>
<img src="<?php echo htmlspecialchars($product['ImagePath']); ?>" alt="Immagine" style="max-width: 100px;"><br> <?php $image_display = '/img/' . ltrim($product['ImagePath'], '/'); ?>
<img src="<?php echo htmlspecialchars($image_display); ?>" alt="Immagine" style="max-width: 100px;"><br>
<input type="file" name="image" accept="image/*"> <input type="file" name="image" accept="image/*">
<input type="hidden" name="current_image" value="<?php echo htmlspecialchars($product['ImagePath']); ?>"></td> <input type="hidden" name="current_image" value="<?php echo htmlspecialchars(basename($product['ImagePath'])); ?>"></td>
<td><button type="submit" name="save">Salva</button></td> <td><button type="submit" name="save">Salva</button></td>
</form> </form>
</tr> </tr>