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

[eluser]Nick_MyShuitings[/eluser]
from the user guide:

Code:
$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:

Code:
$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)


Messages In This Thread
Need a simple download tutorial - by El Forum - 05-06-2011, 10:40 PM
Need a simple download tutorial - by El Forum - 05-07-2011, 07:23 AM
Need a simple download tutorial - by El Forum - 05-08-2011, 05:05 AM
Need a simple download tutorial - by El Forum - 05-08-2011, 07:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB