CodeIgniter Forums
Download helper, using force_download() - file corrupt after opening it - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Download helper, using force_download() - file corrupt after opening it (/thread-52690.html)



Download helper, using force_download() - file corrupt after opening it - El Forum - 06-21-2012

[eluser]Brad K Morse[/eluser]
I manually uploaded files to a server using Transmit, auto detect (file settings).

Then I use the download helper lib to force download the file when a user clicks on a link, which ties to the file's ID in the database.

If I go directly to the file URL path, for example: domain.com/directory/file.pdf, it shows up fine in the browser.

When I click the link that downloads that same file to my desktop, then I open it, it says it is corrupted. This happens to all the files.

What might be possible causes to this problem?

Code:
$this->load->helper('download');
$document = $this->documents->get_document($id);

$data = file_get_contents(base_url() . "uploads/" . $document->file_name);
$name = $document->file_name;

force_download($name, $data);



Download helper, using force_download() - file corrupt after opening it - El Forum - 06-21-2012

[eluser]Otemu[/eluser]
Hi,

If you can copy the link for download and it opens in your browser then there a chance it could be that the adobe package is corrupted on your desktop. Try download the file again but instead of using adobe to open it use your web browser instead.


Download helper, using force_download() - file corrupt after opening it - El Forum - 06-21-2012

[eluser]Brad K Morse[/eluser]
Thanks! I think that was the problem. Worked fine in Firefox and in IE, but not Chrome for my Mac.


Download helper, using force_download() - file corrupt after opening it - El Forum - 08-16-2012

[eluser]zwadder[/eluser]
I had a problem with downloading xls files, they were corrupted. This did fix it: http://www.innovativephp.com/image-downloading-issue-codeigniter-download-helper/
only added the ob_clean() part to the download_helper and it works now fine.
Only when there is an update I will lose it :-(


Download helper, using force_download() - file corrupt after opening it - El Forum - 08-16-2012

[eluser]NeoArc[/eluser]
Try using FCPATH instead of base_url().