Welcome Guest, Not a member yet? Register   Sign In
Need a simple download tutorial


I am new to CodeIgniter, I have searched and searched the net looking for a simple tutorial for downloading a file and haven't found anything that shows or explains how force_download works properly. I am looking for a tutorial that shows model, controller and view. I have manage to work out how to upload files but am struggling to know what to do with force_download and how this interacts with the model and display an output in the view!

And I suggest to anyone who is an expert on CodeIgniter to write a beginners guide the user guide is good but for someone completely new to CodeIgniter and teachers who are new to CodeIgniter that have to teach it would find a beginners guide extremely helpful and would prevent posts like this in the future!

Thank you in advance!

from the user guide:

$data = file_get_contents("/path/to/photo.jpg"); // Read the file's contents
$name = 'myphoto.jpg';

force_download($name, $data);

So... for a file download... lets say you have controller files, with function index which calls view list. Lets go farther and say that you called a db function where you have the names of all the downloadable files stored in a table, with id, name, path.

So in our view list.php we'd run a simple foreach and print out some nice links using the name of the file and the id, and direct them to controller's download method.

Download method will us the id it gets from the url to grab the info out of the model, lets say assigning it to param $file_data... Then the download code would look like this:

$data = file_get_contents($file_data->path); // Read the file's contents
$name = $file_data->name;

force_download($name, $data);

And the end user result, would be that when they click the download link, they don't actually redirect, but the file just downloads nice and pretty....

The end.

(I'm a bit busy to draft this up in super fancy tutorial-ness, but this should do the trick)

Thank you so much! That is exactly what I was looking for!

I award myself three points then.

Theme © iAndrew 2016 - Forum software by © MyBB