Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/01/2005, 06:42
godot
 
Fecha de Ingreso: enero-2005
Mensajes: 24
Antigüedad: 19 años, 3 meses
Puntos: 0
ahí va el código

session_start();

require_once("../classes/database.php");
$database = new database();

if ($_SESSION["usertype"]!="cliente")
require_once("../checklogin.php");
else
require_once("../online/checklogin.php");

require_once("../classes/configuracion.php");

$id= $_GET["id"];

if ($_SESSION["usertype"]!="cliente" || ($_SESSION["usertype"]=="cliente" && $id==$_SESSION["grupo"])){
session_write_close();
//Datos de fichero ... ruta+nombre
$filename=$file;
$ruta= $rutaDoc.$id."/".$tipo_doc."/".$filename;

//Comprobamos si el fichero es válido y si existe
if( $filename == "" ) {
echo "<html><body>ERROR: Falta el nombre de fichero</body></html>";
exit;
}

$ext = substr( $filename,-3 );
switch( $ext ){
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}

//Se envían las cabeceras...
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: $ctype");
$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
//en filename=documento, se puede dejar así, o poner el nombre del documento, o cualquier otra cosa
if ( (is_integer(strpos($user_agent, "msie") ) ) && (is_integer( strpos($user_agent, "win") ) ) ) {
header( "Content-Disposition: ; filename=".$filename );
} else {
header( "Content-Disposition: attachment; filename=".$filename );
}
header("Content-Transfer-Encoding: binary");

header("Content-Length: ".filesize($ruta));

readfile($ruta);
exit();
} else {
echo "<script>alert('No tiene permiso para ver este documento');window.close();</script>";
exit();
}
?>