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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| <?php
include('config2.php');
if (isset($_POST['submit'])) {
$link = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $link);
$titles = isset($_POST['title']) ? $_POST['title'] : array();
$delFlags = isset($_POST['delFlag']) ? $_POST['delFlag'] : array();
$imageNames = isset($_POST['imageName']) ? $_POST['imageName'] : array();
$order = 1;
for ($i = 0; $i < count($titles); $i++) {
// local variables
$title = addslashes($titles[$i]);
$delFlag = $delFlags[$i];
$imageName = $imageNames[$i];
$imageName = @explode(',', $imageName);
$status = $imageName[1];
$imageName = $imageName[0];
$imgid = substr($imageName, 0, strlen($imageName) - 4);
$imgid = substr($imgid, 6);
// check the status and do accordingly
if ($status == 'new' && $delFlag == '1') {
$query = "INSERT INTO images(`order`, `title`) VALUES ($order, '$title')";
mysql_query($query);
// nouvelle entree bdd OK
$imgid = mysql_insert_id();
$new_image_name = $title .'.jpg';
// Copie l'image dans le dossier photos OK
copy('photos/temp/' . $imageName, 'photos/' . $new_image_name);
// Vire le fichier temporaire OK
unlink('photos/temp/' . $imageName);
// image suivante OK
$order++;
}
else if ($status == 'old' && $delFlag == '1') {
$new_image_name = $title .'.jpg';
$new_image_name_bdd = $title ;
$query = "UPDATE images SET `order` = '" . mysql_real_escape_string($order) . "', `title` = '" . mysql_real_escape_string($new_image_name_bdd) . "' WHERE `title` = '" . mysql_real_escape_string($imageName) . "'";
mysql_query($query);
echo $query;
echo mysql_error;
// renomme l'image dans le dossier photos OK
rename('photos/' . $imageName, 'photos/' . $new_image_name);
// increment the order variable
$order++;
}
// Vire l'image et l'entree de la base de donnee OK
else if ($status == 'old' && $delFlag == '0') {
$query = "DELETE FROM images WHERE title = '$title'";
mysql_query($query);
$image_name = $title . '.jpg';
unlink('photos/' . $image_name);
}
}
}
header('Location: pics.php');
?> |
Partager