-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.php
116 lines (52 loc) · 1.57 KB
/
update.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
//update.php
include('database_connection.php');
if(isset($_POST["image_id"]))
{
$old_name_appoggio = get_old_image_name($connect, $_POST["image_id"]);
$old_name_array = explode(".", $old_name_appoggio);
$old_name = $old_name_array[1]; //pos 0=cartella, pos 1=nome file
$file_array = explode(".", $old_name);
$file_extension = end($file_array);
$new_name = $_POST["image_name"] . '.' . $file_extension;
$old_name = $old_name . '.' . $file_extension;
$query = '';
$cartella=$old_name_array[0];
if($old_name != $new_name)
{
$old_path = 'files/' .$cartella. $old_name;
$new_path = 'files/' .$cartella. $new_name;
if(rename($old_path, $new_path))
{
$query =
UPDATE tbl_image
SET image_name = '".$new_name."', image_description = '".$_POST["image_description"]."'
WHERE image_id = '".$_POST["image_id"]."'
";
}
}
else
{
$query =
UPDATE tbl_image
SET image_description = '".$_POST["image_description"]."'
WHERE image_id = '".$_POST["image_id"]."'
";
}
$statement = $connect->prepare($query);
$statement->execute();
}
function get_old_image_name($connect, $image_id)
{
$query =
SELECT T.image_name, I.cartella FROM tbl_image T INNER JOIN immagini_x_cartelle I ON T.image_name = I.immagine WHERE T.image_id = '".$image_id."'
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
return $row["cartella"].".".$row["image_name"];
}
}
?>