if(isset($_GET['id'])){
$query = $mysqli->query('SELECT * FROM tabella WHERE id_img='.(int)$_GET['id']) or die($mysqli->error);
if($query->num_rows>0){
$result = $query->fetch_object();
header('Content-type: image/png');
header("Content-Disposition: attachment; filename='$result->titolo';");
echo $result->img;
}else die('Errore, id invalido o non trovato');
}else die('Errore, id non settato');