![]() |
Need help getting Force Download to work - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Need help getting Force Download to work (/showthread.php?tid=35654) |
Need help getting Force Download to work - El Forum - 11-06-2010 [eluser]brent7779[/eluser] Please excuse my newbieness, but this seems so very simple, i copied the code directly from the user guide and i can't understand why this function doesn't auto download as soon as the "download.php" controller is called up, i want to avoid the download being possible by using a direct url like - http://www.mysite.com/index.php/download/getpdf... so, I put the underscore in front of the function name and put that function inside of the index function for this controller, so what gives? nothing happens at all, I get no php errors or anything, its not the wrong path to file, just nothing happens... <?php class Download extends Controller { function index() { $this->load->helper('download'); $this->load->view('header_view'); $this->load->view('download_view'); $this->load->view('footer_view'); function _getpdf() { $data = file_get_contents("../../filename.pdf"); // Read the file's contents $name = 'filename.pdf'; force_download($name, $data); } } } ?> Need help getting Force Download to work - El Forum - 11-06-2010 [eluser]vitoco[/eluser] First of all, was a bad copy paste... 1.- force the download on the the index method Code: <?php 2.- force the download on the the get_pdf method, that will be called in a view Code: <?php Need help getting Force Download to work - El Forum - 11-06-2010 [eluser]brent7779[/eluser] Thanks alot vitoco for your quick response, I can't wait to try your solution, I will post back as soon as I can try it! Oh, one more thing, it was my understanding that in order to make a function private the underscore had to precede everything else, no? "_getpdf()" and if I call the method from a view, I can't use the underscore in the path cause it will give 404 error right? Code: <?php I would like to avoid making the user click another link, they have already filled out my form and gone through paypal at this point, that's why I wanted the download method nested in the index method for that controller and auto download. Thanks again, I really appreciate you guys helping out the newbies here! |