CodeIgniter Forums
Download Files Corrupted - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Download Files Corrupted (/showthread.php?tid=57927)



Download Files Corrupted - El Forum - 04-27-2013

[eluser]GabrieleMartino[/eluser]
Hello,

my controller state

public function download_file(){
$this->load->helper('download');

$path = './uploads/'.$this->session->userdata('chat_id').'/files';
$path_complete = $path.'/';
$handle = opendir($path_complete);
$files = glob($path_complete.'*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file)Wink{
$data = file_get_contents($file); // Read the file's contents
$name = $file;
force_download($name, $data);

}
}
}

I tried to downloadimages and files. Do not work (corrupted and incomplete).


Thanks


Download Files Corrupted - El Forum - 04-27-2013

[eluser]GabrieleMartino[/eluser]
I resolved adding

Code:
obclean();

and

Code:
flush();

before

Code:
exit($data);

in the helper.