Welcome Guest, Not a member yet? Register   Sign In
force_download + CI 1.6.0
#1

[eluser]somewhatjaded[/eluser]
I was pulling my hair out trying to get force_download to work with CI 1.6.0, in both IE7 & FF 2.

FF2 would claim that the tmp file wasn't available, and IE7 would just go to a 'page unavailable', even when I wasn't trying to load a view (which isn't possible when using force_download anyways).

The fix I found was that the force_download function never exited.

To fix:

in system\helpers\download_helper.php, about line 94:

Code:
echo $data;
exit(); //<---- ADD THIS LINE

This seemed to do the trick in both browsers.

note: I'm not sure if this is fixed in CI 1.6.1 or not.
#2

[eluser]Derek Allard[/eluser]
I like this suggestion, and its been incorporated into CI. Thanks.
#3

[eluser]Digitalman65[/eluser]
[quote author="Derek Allard" date="1208487528"]I like this suggestion, and its been incorporated into CI. Thanks.[/quote]


I wish it had been made an optional argument because I need to do some processing after the force_download but can't. For instance, after the force_download, I want to delete the file. Since processing stops at this point, I can't use force_download.

I'm making it an argument in my copy of CI. Unfortunately my copy of CI will now be out of sync with the official CI; not something I enjoy having, I must say.

function force_download($filename = '', $data = '', $exit_now = TRUE)
:
:
if ($exit_now)
{
exit($data);
}
else
{
echo ($data);
}
}


It's just very important that the developer doesn't produce any additional output after force_download otherwise it will corrupt the file data being downloaded.
#4

[eluser]somewhatjaded[/eluser]
From what I understand (http://ellislab.com/codeigniter/user-gui...elper.html), there is no file created when using this function, it's simply a http output with the correct headers for browser download.

To output an actual file, you have to read the contents in first, so if you wanted to delete the file afterwards, I'd say you really have to delete the file BEFORE, by reading the file contents into a temp var, deleting the file, then outputting the temp var to the force_download function, should solve your problem.

I can see how you might want to do something after you forced the download, but then you run the chance of corrupting your output, as you pointed out. I think that having the optional exit might lead to more problems for the developer in the long run.

If you're working with files, be sure to take a look at http://ellislab.com/codeigniter/user-gui...elper.html
#5

[eluser]Digitalman65[/eluser]
[quote author="somewhatjaded" date="1219441448"]from what I understand (http://ellislab.com/codeigniter/user-gui...elper.html), there is no file created when using this function, it's simply a http output with the correct headers for browser download. To output an actual file, you have to read the contents in first, so if you wanted to delete the file afterwards, I'd say you really have to delete the file BEFORE, by reading the file contents into a temp var, deleting the file, then outputting the temp var to the force_download function, should solve your problem. I can see how you might want to do something after you forced the download, but then you run the chance of corrupting your output, as you pointed out. I think that having the optional exit might lead to more problems for the developer in the long run. If you're working with files, be sure to take a look at http://ellislab.com/codeigniter/user-gui...elper.html[/quote]

I totally agree. It's definitely safer to exit in the force_download function. In fact, given what you said, I'm going to revert back to the original Ci code and refactor my function to follow your suggestion - which I like a lot better than my solution. Thanks for the reply.
#6

[eluser]javigarrido[/eluser]
Hi, my problem is a diffrent one:

the function force_download simply doesn't make any output.

$this->load->helper('download');
$data = file_get_contents("modulos/".$filename); // Read the file's contents
force_download($filename, $data);
echo $data."/".$filename;

Here i just get a white screen, but the file content are show (well you now, the strange codified content Smile
I think it is simple enought, i just want the file downloaded with no other efect, ami doing something wrong?
#7

[eluser]mehdy[/eluser]
please help me to code view file for force_download.
thank you




Theme © iAndrew 2016 - Forum software by © MyBB