-
Notifications
You must be signed in to change notification settings - Fork 2
/
elimina_prodotto.php
40 lines (32 loc) · 1.11 KB
/
elimina_prodotto.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once './scripts/php/Sessione.php';
Sessione::startSession();
Sessione::reservedPage();
if (!(array_key_exists('id', $_REQUEST) && is_numeric($_REQUEST['id']))) {
header("Location: ./404.php", 404);
exit;
}
$id = $_GET['id'];
require_once './scripts/php/connection.php';
$connection = new MySqlDatabaseConnection("localhost", "mifranco", "mifranco", "Aideebe4esooDuqu");
$connection->connect();
$images = $connection->getProductImages($id);
$result = $connection->deleteProdotto($id);
$connection->close();
$deleteResult = true;
$trashFolder = "./deleted-catalog-images/";
if (!is_dir($trashFolder)) {
mkdir($trashFolder);
}
if (!is_dir("./deleted-catalog-images/thumbnails")) {
mkdir("./deleted-catalog-images/thumbnails");
}
foreach ($images as $value) {
$deleteResult = $deleteResult && rename("./images/catalogo/". $value, $trashFolder. $value);
}
$previousPage = $_GET['previous'];
if ($result && $deleteResult) {
header("location: " . $previousPage);
} else {
echo "Qualcosa è andato storto. Contatta il tuo sysadmin di fiducia, oppure <a href=\"./index.php\">torna alla home</a>";
}