Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/01/2013, 15:42
Avatar de acoevil
acoevil
 
Fecha de Ingreso: julio-2008
Ubicación: localhost/colombia/sevillaValle.php
Mensajes: 1.123
Antigüedad: 15 años, 9 meses
Puntos: 32
Descargar corrupta de archivos

Buenas tardes a todos.

Encontre un Codigo en php que permite forzar las descargas con php pero al momento abrir cualquier tipo de archivo, abre corrupto.

Este es el codigo que estoy usando, muchas gracias por su colaboracion.


Código PHP:

<?php
ob_start
();
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        $_GET
['file'] = 'img.jpg';
        
//$archivo = 'word.docx';
        
$root "";
        
$file basename($_GET['file']);
        
$path $root $file;
        
$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";
            }
            
// Set Headers
            
header("Content-Type: $type");
            
header("Content-Disposition: attachment; filename=$file");
            
header("Content-Transfer-Encoding: binary");
            
header("Content-Length: " $size);
            
// Download File
            
readfile($path);
        } else {
            die(
"File not exist !!");
        }
        
?>
    </body>
</html>
<?php
$c 
ob_get_clean();
echo 
$c;

?>
__________________
Como presentar nuestros datos por medio de tablas . clase Aco_DataGrid Version 1.4