Problem to download php files I get ZERO BYTES

0

I'm trying to download files. I recognize the names of the entire file. But when downloading it does it in ZERO BYTES. Let's see if someone sees something irregular. Thank you!

The file is inside the / files / directory on the site.

<?php
Application::Uses('com.web.WebPage');

class download extends TVisualComponent{

    public $package='app.admin.ajax';
    public $respuesta=array();

    public function run(){

        $dir_subida = Application::getPath('files');
        $file = "..".$dir_subida."/".$_GET['file'];

        $file_name=explode("track_",$file);

        header("Content-type: octet/stream");
        header("Content-disposition: attachment; filename=".$file_name[1].";");
        header("Content-Length: ".filesize($file));

        ob_clean();
        flush();

        readfile($file);
        exit;
    }
}
    
asked by Juan Salvador Portugal 26.11.2018 в 04:15
source

1 answer

0
$dir_subida = Application::getPath('files');
$file = "..".$dir_subida."/".$_GET['file'];
$file_name=explode("track_",$file);

if (file_exists($file_name[1])) {
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;filename='.$file_name[1]);
    header('Content-Length: ' . filesize($file_name[1]));
    readfile($file_name[1]);
    exit;
}
    
answered by 26.11.2018 в 18:57