Welcome Guest, Not a member yet? Register   Sign In
Download helper not helping
#1

[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.
#2

[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.
#3

[eluser]jinmatt[/eluser]
yes
#4

[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è
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB