Пример #1
0
<?php 
require_once '../includes/initialize.php';
if (empty($_GET['id']) && $_GET['comid']) {
    $session->message("No Photograph ID was provided");
    redirect_to('list_photos.php');
}
$photo = Main_pictures::find_by_id($_GET['id']);
if ($photo && $photo->destroy()) {
    /////////////////////////////////////////////////////////
    $foto = Com_pictures::find_by_id_and_comid($_GET['id'], $_GET['comid']);
    global $database;
    $sql = "DELETE FROM com_pictures WHERE comid='" . $database->escape_value($_GET['comid']) . "'";
    $work = $database->query($sql);
    $sql2 = "DELETE FROM comments WHERE comid='" . $database->escape_value($_GET['comid']) . "'";
    $work2 = $database->query($sql2);
    if ($foto && $work && $work2) {
        $target_path = SITE_ROOT . DS . 'public' . DS . $foto->image_path();
        return unlink($target_path) ? true : false;
    }
    ////////////////////////////////////////////////////////////////
    $session->message("The photo {$photo->filename} was deleted");
    redirect_to("list_photos.php");
} else {
    $session->message("The photo could not be deleted.");
    redirect_to('list_photos.php');
}
if (isset($database)) {
    $database->close_connection();
}