CodeIgniter Forums
Download helper not helping - 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 helper not helping (/showthread.php?tid=37444)



Download helper not helping - El Forum - 01-10-2011

[eluser]jinmatt[/eluser]
I don't have much experience in working with CodeIgniter, but recently I'm using CodeIgniter in one of my company projects. I need help in Downloading a file.

I uploaded a file to a directory at the root of the CI with the do_upload(). The upload is working fine and when I downloaded the file from the directory using a ftp client the file is readable and ok.

But when I used the Download helper and tried to download as follows:
Code:
$data = file_get_contents("./uploads/{$file_name}");
$name = $file_name;

force_download($name, $data);

the download occurs but the file gets changed. i.e. if I download a .doc file, when I open it, it gives me some gibberish texts and tells to select a encoding type.

is this the right way to do it? or should I just provide direct link to the file to make it download than using the download helper?

Thanks.


Download helper not helping - El Forum - 01-10-2011

[eluser]Ochetski[/eluser]
Are your uploads folder and index.php (that takes you to codeigniter) in the same place?

Remember that NO text can be written or view included before force download command. It will need a specific header that will be broke if any text came first.


Download helper not helping - El Forum - 01-10-2011

[eluser]jinmatt[/eluser]
yes


Download helper not helping - El Forum - 01-10-2011

[eluser]Cristian Gilè[/eluser]
Check the mime content type of the file you want to download with the mime_content_type() function and search for the returned type in the config/mimes.php file.

Cristian Gilè


Download helper not helping - El Forum - 01-13-2011

[eluser]jinmatt[/eluser]
mime_content_type() is giving "Fatal error: Call to undefined function mime_content_type()..." :red:

btw config/mimes.php already have all the mime types required for common file types like doc, docx, pdf, etc.