CodeIgniter Forums
force_download problem? - 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: force_download problem? (/showthread.php?tid=51417)



force_download problem? - El Forum - 05-03-2012

[eluser]Unknown[/eluser]
Hi! Im new on this Framework and Forum and I'm looking for someone who can help me.

I have a problem with the helper download. I was trying to download a text file with a special extension(the specific of my application) from my webpage, but the function force_download enter a blank space at the beginning of the file content. Is it possible that this problem was caused by the extension? Is this any bug, what i should do?

The code of the controller is this:


Code:
function descarregar(){
      $this->load->helper('download');
      
      $name=$this->input->post('descarregarPOGO');
      $base_url='/opt/lampp/htdocs/uploads/';
      $url=$base_url.$name;

      $data=file_get_contents($url);

      force_download($name,$data);
    }

I put an echo of $data in this piece of code and the result seams to be correct, in $data figures the content of the file without the blank space.

Thank you for your help and sorry about my english!


force_download problem? - El Forum - 05-03-2012

[eluser]Unknown[/eluser]
It seams that I output a blank space before exit($data);

I solved my problem adding the function ob_clean(); before exit($data); line on the force_download function of CodeIgniter Framework.