Welcome Guest, Not a member yet? Register   Sign In
How can I download a file and load a view? is it possible?
#1

[eluser]jpganz[/eluser]
Hi,

Ive been trying to download a file and load a view, but doesnt work, seems like after the force_download runs nothing else is preceded... any other way to do it? I also tried loading the view and inside the view after all the html code foce the download, the result.. the same white screen.

Any help would be appreciated.
Thanks!

here is my code

Code:
$this->load->helper('download');
$img_url = base_url().'images/myimage.jpg';
$data = file_get_contents($img_url);
$name = 'promocion_flights.jpg';
force_download($name, $data);
$this->load->view('views/my_view',$data);
#2

[eluser]PhilTem[/eluser]
That's basic HTML writing. You need to have something like this in the <head> part of your final page:

Code:
<meta http-equiv="refresh" content="5; url=http://www.example.com/path/to/downloadable/file">

That line of code will open the browser's file-download popup after 5 seconds.
#3

[eluser]jpganz[/eluser]
Thanks for your answer, the problem is that I want to download the file, in this case it only shows me the image in the browser, doesnt download it.. .any other way to do it?

Thanks
#4

[eluser]Mirge[/eluser]
You load your view, which would contain something like "Your download will start in 5 seconds..." (I assume).

Then for your download, like Phil mentioned, you'd use the HTML redirect.

Code:
<meta http-equiv="refresh" content="5; url=http://www.example.com/controller/method/argument/">

And in your method, that's where you call the force_download() function.

---

In other words, load your view. Your view contains an HTML redirect to the controller that forces a download.
#5

[eluser]Abel A.[/eluser]
You would need to change your php headers to force the download. I quick google will show you some examples.

http://www.ryboe.com/tutorials/php-heade...e-download




Theme © iAndrew 2016 - Forum software by © MyBB