<?php require_once("../../includes/initialize.php"); ?>
<?php if(!$sesion->esta_logueado())    { redireccionar_a("login.php"); } ?>
<?php
if (isset($_GET['id']) && isset($_GET['comunicacion_id']) ){
    $id=$_GET['id'];  
    $comunicacion_id=$_GET['comunicacion_id'];  
    $sql="select * from fotos where comunicacion_id= {$comunicacion_id} and renglon_id={$id}";    
    $rs = mysqli_query( $conn,$sql);
    $row = mysqli_fetch_row($rs);
    $file = $row[1];
    $path = '../../images/'.$file;
}
else
{
    exit();
}
$root = '../../images/';
$path = $root.$file;

//echo strtolower(array_pop(explode('.',$file)));
$ext=substr($file, -3, 3);
$type='';


if (is_file($path)) 
{
     $size = filesize($path);
     if (function_exists('mime_content_type')) {
        $type = mime_content_type($path);
     } else if (function_exists('finfo_file')) 
                {    $info = finfo_open(FILEINFO_MIME);
                     $type = finfo_file($info, $path);
                     finfo_close($info);
                }
     if ($type == '') 
     {
     $type = "application/force-download";
     }

switch ($ext)
{
    case "pdf":
   // Definir headers
   //echo 'pdf';
        header( "Content-type: application/pdf" ); 
        header( 'Content-Length: $size'); 
        header( 'Content-Disposition: inline; filename='.$file ); 
	readfile($path);
        break;
    case "jpg":
    case "gif":
    case "bmp":
    case "png":   
    $size = filesize($path);
        header('Content-type: image/'.$ext);
//        header( "Content-type: application/pdf" ); 
        header( 'Content-Length: $size'); 
        header( 'Content-Disposition: inline; filename='.$file ); 
	readfile($path);
        break;
    default:
        $size = filesize($path);
        header("Content-Type: application/force-download");
        header('Content-Disposition: attachment; filename=$file');
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . $size);  
        readfile($path);
        break;
}       
} else 
{
 die("El archivo '$path' no existe.");
}
?>