Welcome Guest, Not a member yet? Register   Sign In
HOW TO FORCE FILE DOWNLOD TO PC
#16

(07-02-2016, 11:21 PM)Wouter60 Wrote: First, make sure that you don't pass the filename directly to your controller, because it becomes part of the url.
The link in your view should be like this:
PHP Code:
echo anchor('download/download_file/' urlencode($filename),$filename);
//the anchor function is in the url helper 

Now, in the controller method, I decode the given filename.
PHP Code:
public function download_file($name)
{
 
     //$name is the encoded filename, passed by the view
 
     $this->load->helper('download');
 
     $path './uploads/docs/' urldecode($name);
 
     if (file_exists($path)) {
 
        force_download($path,NULL);
 
     }
 
     else {
 
        show_error('File not found!');
 
        die();
 
     }

Let me know if this helps.

I have tried the code but still its not working. Am using CI 2.2.6 When i click on the link it redirects to black page and the this "http://codeigniter/index.php/download/download_file/january2013.pdf" is what is the url, the file is not downloaded
Reply


Messages In This Thread
HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 06-27-2016, 02:10 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by PaulD - 06-27-2016, 04:26 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 06-29-2016, 03:11 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by PaulD - 06-29-2016, 03:51 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by InsiteFX - 06-29-2016, 06:07 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 07-17-2016, 05:05 AM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 07-01-2016, 03:37 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by Wouter60 - 07-02-2016, 05:34 AM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 07-02-2016, 07:58 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by Wouter60 - 07-02-2016, 11:21 PM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 07-17-2016, 05:19 AM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by PaulD - 07-03-2016, 08:48 AM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by kwangu - 07-11-2016, 02:12 AM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by InsiteFX - 07-11-2016, 02:54 AM
RE: HOW TO FORCE FILE DOWNLOD TO PC - by InsiteFX - 07-17-2016, 05:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB