get_row($s, ARRAY_A); if (strlen($r['archivo'])>3) @unlink('../uploads/noticias/'.$r['archivo']); $s = "UPDATE noticias SET archivo = '' WHERE id = $id"; $db->query($s); header('Location: ficha_noticia.php?id='.$id); exit(); } if(isset($_GET['elimfotopr'])) { $id = $_GET['elimfotopr']; $s = "SELECT foto FROM noticias WHERE id = $id"; $r = $db->get_row($s, ARRAY_A); if(strlen($r['foto'])>3) @unlink('../uploads/noticias/'.$r['foto']); $s = "UPDATE noticias SET foto = '' WHERE id = $id"; $db->query($s); header('Location: ficha_noticia.php?id='.$id); exit(); } if(isset($_GET['elimfoto'])) { $id_noticia = $_GET['noticia']; $id_foto = $_GET['elimfoto']; $s = "SELECT * FROM noticias_fotos WHERE id=".$id_foto; $r = $db->get_row($s, ARRAY_A); @unlink('../uploads/noticias/'.$r['foto']); $s = "DELETE FROM noticias_fotos WHERE id=".$id_foto; $db->query($s); header('Location: ficha_noticia.php?id='.$id_noticia); exit(); } if(isset($_POST['subir'])) { if(is_file($_FILES["foto"]["tmp_name"])) { $f = $_FILES["foto"]; $strfile = date("YmdHis")."-".$f['name']; copy($f["tmp_name"], "../uploads/noticias/".$strfile); $id_noticia = $_POST['id_noticia']; $s = "INSERT INTO noticias_fotos (foto, id_noticia, fechaupload) VALUES ('".$strfile."', ".$id_noticia.", NOW())"; $db->query($s); header('Location: ficha_noticia.php?id='.$id_noticia); exit(); } } if(isset($_POST['guardar'])) { $id = $_POST['id']; if($id == 0) { $s = "INSERT INTO noticias (fcreacion) VALUES (NOW())"; $db->query($s); $id = $db->insert_id; } $fec = explode("/", $_POST['fecha']); $fecha = $fec[2]."-".$fec[1]."-".$fec[0]; //URI $str = htmlentities($_POST['titulo'], ENT_COMPAT, "UTF-8"); $str = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str); $str = html_entity_decode($str); $str = strtolower($str); $str = str_replace(" ", "-", $str); $str = str_replace("/", "-", $str); // $s = "UPDATE noticias SET titulo = '".$_POST['titulo']."', texto = '".$_POST['texto']."', fecha = '".$fecha."', uri = '".$str."', fupdate = NOW() WHERE id = $id"; $db->query($s); //upload foto principal if(is_file($_FILES["fotopr"]["tmp_name"])) { $f = $_FILES["fotopr"]; $strfile = date("YmdHis")."-".$f['name']; copy($f["tmp_name"], "../uploads/noticias/".$strfile); $s = "UPDATE noticias SET foto = '".$strfile."' WHERE id = $id"; $db->query($s); } //upload archivo adjunto if(is_file($_FILES["archivo"]["tmp_name"])) { $f = $_FILES["archivo"]; $strfile = date("YmdHis")."-".$f['name']; copy($f["tmp_name"], "../uploads/noticias/".$strfile); $s = "UPDATE noticias SET archivo = '".$strfile."' WHERE id = $id"; $db->query($s); } header('Location: ficha_noticia.php?id='.$id); exit(); } $id = 0; if(isset($_GET['id'])) { $id = $_GET['id']; $s = "SELECT *, DATE_FORMAT(fecha, '%d/%m/%Y') as fecha2 FROM noticias WHERE id = $id"; $r = $db->get_row($s, ARRAY_A); } include("includes/header.inc.php"); ?>
Ficha noticia
RECOMENDACIÓN: Subir las fotos en tamaño de 800x600px e intentar
que no pesen más de 200kb para que cueste menos cargar las páginas.
3) { ?>

foto actual
Eliminar foto

3) { ?>

Archivo actual - eliminar

0) { $s = "SELECT * FROM noticias_fotos WHERE id_noticia = $id"; $fotos = $db->get_results($s, ARRAY_A); ?>
Galería de fotos
0) { ?>

Listado de fotos: