HEX
Server: Apache
System: Linux pdx1-shared-a1-06 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: ednermusika (2886498)
PHP: 8.4.2
Disabled: NONE
Upload Files
File: /home/ednermusika/ednergranados.com/admin/galeria_detalle_upload.php
<?php 
if (!isset($_SESSION)) {
  session_start();
}
?>
<?php require_once('../Connections/con_edner.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
include('funciones_archivos.php');
$gal_consecutivo 	=  $_POST['item_id'];//$_SESSION['eve_consecutivo'];

$slash					= "/";
$ruta_server 			= $_SERVER['DOCUMENT_ROOT'].$slash;
$raiz					= "../";
$carpeta_galerias		= "galerias";
$carpeta_galerias_fotos	= "galeria_".$gal_consecutivo;
$uploaddir	= $raiz.$carpeta_galerias.$slash.$carpeta_galerias_fotos.$slash;
if (!is_dir($raiz.$carpeta_galerias))
	mkdir($raiz.$carpeta_galerias, 0755);
if (!is_dir($uploaddir))
	mkdir($uploaddir, 0755);
?>
<?php

// If you want to ignore the uploaded files, 
// set $demo_mode to true;

$demo_mode = false;
$upload_dir = $uploaddir;
$allowed_ext = array('jpg','jpeg','png','gif');


if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
	exit_status('Error! Wrong HTTP method!');
}


if(array_key_exists('pic',$_FILES) && $_FILES['pic']['error'] == 0 ){
	
	$pic = $_FILES['pic'];

	if(!in_array(get_extension($pic['name']),$allowed_ext)){
		exit_status('Only '.implode(',',$allowed_ext).' files are allowed!');
	}	

	if($demo_mode){
		
		// File uploads are ignored. We only log them.
		
		$line = implode('		', array( date('r'), $_SERVER['REMOTE_ADDR'], $pic['size'], $pic['name']));
		file_put_contents('log.txt', $line.PHP_EOL, FILE_APPEND);
		
		exit_status('Uploads are ignored in demo mode.');
	}
	
	
	// Move the uploaded file from the temporary 
	// directory to the uploads folder:
	
	if(move_uploaded_file($pic['tmp_name'], $upload_dir.$pic['name'])){
		
		$file = $upload_dir.$pic['name']; 
		$img_original=$pic['name']; 
		/*CODIGO PARA HACER THUMBNAILS*/
		$tn_ancho 	= 252;
		$tn_altura	= 168;
		$img_ancho	= 650;
		$img_altura	= 550;
		$orientacion	= f_recuperar_orientacion ( $file );
		if ($orientacion=='v'){
			$img_ancho 	= 550;
			$img_altura	= 650;
			$tn_ancho 	= 168;
			$tn_altura	= 252;
		}
		f_generar_thumbnail($uploaddir, $img_original, "tn_", $tn_ancho, $tn_altura);
		f_generar_thumbnail($uploaddir, $img_original, "img_", $img_ancho, $img_altura);
		$tn_ancho_crop 	= 168;
		$tn_altura_crop	= 168;
		f_generar_thumbnail_crop($uploaddir, "tn_".$img_original, "", $tn_ancho_crop, $tn_altura_crop);
		/*CODIGO PARA HACER THUMBNAILS*/
		
		$thumbnail 		= "tn_".$img_original;
		$imagen 		= "img_".$img_original;
		$ruta			= $carpeta_galerias.$slash.$carpeta_galerias_fotos.$slash;
		$gal_descripcion	= $_POST['titulo_id'];
		
		mysql_select_db($database_con_edner, $con_edner);
		$query_MAXIMO = sprintf("SELECT IFNULL(MAX(gad_consecutivo),0)+1 as MAXIMO FROM galeria_detalle WHERE gal_consecutivo = %s", GetSQLValueString($gal_consecutivo, "int"));
		$MAXIMO = mysql_query($query_MAXIMO, $con_edner) or die(mysql_error());
		$row_MAXIMO = mysql_fetch_assoc($MAXIMO);
		$totalRows_MAXIMO = mysql_num_rows($MAXIMO);

		$querySQL 		= sprintf("INSERT INTO galeria_detalle (gal_consecutivo, gad_consecutivo, gal_id, gad_descripcion, gad_ruta, gad_thumbnail, gad_imagen, gad_orientacion, gad_activo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
				GetSQLValueString($gal_consecutivo, "int"),
                GetSQLValueString($row_MAXIMO['MAXIMO'], "int"),
				GetSQLValueString($row_MAXIMO['MAXIMO'], "int"),
				GetSQLValueString($gal_descripcion, "text"),
                GetSQLValueString($ruta, "text"),
                GetSQLValueString($thumbnail, "text"),
                GetSQLValueString($imagen, "text"),
                GetSQLValueString($orientacion, "text"),
                GetSQLValueString(1, "int"));
		
		mysql_select_db($database_con_edner, $con_edner);
		$Result1 = mysql_query($querySQL, $con_edner) or die(mysql_error());
		
		/***************ACTUALIZAR EL THUMBNAIL DE LA GALERIA***************************/
		mysql_select_db($database_con_edner, $con_edner);
		$query_galeria = sprintf("SELECT gal_thumbnail FROM galeria WHERE gal_consecutivo = %s", GetSQLValueString($gal_consecutivo, "int"));
		$galeria = mysql_query($query_galeria, $con_edner) or die(mysql_error());
		$row_galeria = mysql_fetch_assoc($galeria);
		$totalRows_galeria = mysql_num_rows($galeria);
		
		$gal_thumbnail = $row_galeria['gal_thumbnail'];
		if ($gal_thumbnail == NULL)
		{
			$querySQL = sprintf("UPDATE galeria SET gal_ruta=%s, gal_thumbnail=%s WHERE gal_consecutivo = %s", GetSQLValueString($ruta, "text"), GetSQLValueString($thumbnail, "text"),GetSQLValueString($gal_consecutivo, "int"));
			mysql_select_db($database_con_edner, $con_edner);
			$Result1 = mysql_query($querySQL, $con_edner) or die(mysql_error());
		}
		
		/***************ACTUALIZAR EL THUMBNAIL DE LA GALERIA***************************/
		
		
		exit_status('Archivos fueron subidos satisfactoriamente!');
	}
	
}

exit_status('Se encontrĂ³ un error al momento de subir!');


// Helper functions

function exit_status($str){
	echo json_encode(array('status'=>$str));
	exit;
}

function get_extension($file_name){
	$ext = explode('.', $file_name);
	$ext = array_pop($ext);
	return strtolower($ext);
}
?>