Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/10/2007, 13:50
Avatar de Seppo
Seppo
 
Fecha de Ingreso: marzo-2005
Ubicación: Buenos Aires, Argentina
Mensajes: 1.284
Antigüedad: 19 años, 1 mes
Puntos: 17
Re: denegar acceso a un directorio con .htaccess y php

En el .htaccess de la carpeta /public_html/downloads ponés "Deny from all"
Y hacés un archivo /public_html/download.php con lo siguiente

Código PHP:
<?php
session_start
();
if (!
$_SESSION['logueado']) { die ('Debés estar logueado para descargar archivos'); }
$archivo $_GET['archivo'];

//cosas de seguridad...
if (strpos($archivo,'../') !== false || substr($archivo,0,10) != 'downloads/') die('Error en la ruta');

//dependiendo del tipo de archivo
header("Content-type: application/octet-stream");
//header('Content-type: application/pdf');

header('Content-Disposition: attachment; filename="' basename($archivo) . '"');

readfile($archivo);

?>