/
home2
/
reumatologia
/
public_html
/
admin
/
Upload File
HOME
<?php require_once('../inc_library.php'); /* obtenemos datos enviados */ $IdCategoria = intval($_REQUEST['IdCategoria']); $Fecha = strval($_REQUEST['Fecha']); $Titulo = strval($_REQUEST['Titulo']); $Copete = strval($_REQUEST['Copete']); $Cuerpo = strval($_REQUEST['Cuerpo']); $Video = strval($_REQUEST['Video']); $EliminarImagen = intval($_REQUEST['EliminarImagen']); $EliminarArchivos = strval($_REQUEST['EliminarArchivos']); $Destacado = intval($_REQUEST['Destacado']); $arrKeywords = $_REQUEST['keyword']; $Submit = (isset($_REQUEST['Submitted'])); /* declaramos e instanciamos variables necesarias */ $err = 0; $oNoticia = new Noticia(); $oNoticias = new Noticias(); $oNoticiaArchivos = new NoticiaArchivos(); $oNoticiaImagenes = new NoticiaImagenes(); $oKeywords = new Keywords(); /* validaciones... */ if ($IdCategoria == '') $err |= 1; if ($Fecha == '') $err |= 2; if ($Titulo == '') $err |= 4; /* si no hay ningun error... */ if ($err == 0) { $Imagen = $_FILES['Imagen-1']; /* si no hay errores... */ if ($Imagen['name'] != '') { if ($Imagen['error'] != 1) { $oUpload = new Image ( $Imagen['name'], $Imagen['tmp_name'], $Imagen['size'], $Imagen['type'], array(Noticia::PathImageBig, Noticia::PathImageThumb), array('jpg', 'jpeg', 'gif', 'png'), array(1200, 1200), array(600, 600), array('Resize', 'Adaptive'), 100 ); } } if (!$oUpload || $oUpload->UploadImage()) { $oNoticia->IdCategoria = $IdCategoria; $oNoticia->Fecha = $Fecha; $oNoticia->Titulo = $Titulo; $oNoticia->Copete = $Copete; $oNoticia->Cuerpo = $Cuerpo; $oNoticia->Video = $Video; $oNoticia->Destacado = $Destacado; $oNoticia->Imagen = $oUpload ? $oUpload->GetNombre() : $oNoticia->Imagen; /* modificamos el registro */ $oNoticia = $oNoticias->Create($oNoticia); if ($oUpload) { $oNoticiaImagen = new NoticiaImagen(); $oNoticiaImagen->IdNoticia = $oNoticia->IdNoticia; $oNoticiaImagen->Imagen = $oUpload->GetNombre(); $oNoticiaImagen->Epigrafe = $Titulo; $oNoticiaImagen->Orden = 0; $oNoticiaImagen = $oNoticiaImagenes->Create($oNoticiaImagen); } $arrArchivos = $_FILES['Archivo']; $count = 0; foreach($_FILES['Archivo']['tmp_name'] as $key => $tmp_name) { if ($_FILES['Archivo']['name'][$key] == '') continue; $oUpload = new Up ( $key.$_FILES['Archivo']['name'][$key], $_FILES['Archivo']['tmp_name'][$key], $_FILES['Archivo']['size'][$key], $_FILES['Archivo']['type'][$key], Noticia::PathFile ); $Nombre = $_REQUEST['NombreArchivo'][$count]; if ($Nombre == '') $Nombre = $_FILES['Archivo']['name'][$key]; if ($oUpload->UploadFile()) { $oNoticiaArchivo = new NoticiaArchivo(); $oNoticiaArchivo->IdNoticia = $oNoticia->IdNoticia; $oNoticiaArchivo->Nombre = $Nombre; $oNoticiaArchivo->Archivo = $oUpload->GetNombre(); /* creamos el registro */ $oNoticiaArchivo = $oNoticiaArchivos->Create($oNoticiaArchivo); } $count++; } if ($arrKeywords) { foreach ($arrKeywords as $keyword) { $oKeyword = new Keyword(); $oKeyword->IdNoticia = $oNoticia->IdNoticia; $oKeyword->Nombre = $keyword; $oKeywords->Create($oKeyword); } } header('Content-type: application/json'); echo json_encode(array("Success" => true, "Error" => "")); } else { header('Content-type: application/json'); echo json_encode(array("Success" => false, "Error" => utf8_encode($err. "Error al procesar la imagen."))); } } else { header('Content-type: application/json'); echo json_encode(array("Success" => false, "Error" => utf8_encode($err. "Error al crear el Noticia."))); } ?>