![]() |
HOW TO FORCE FILE DOWNLOD TO PC - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: HOW TO FORCE FILE DOWNLOD TO PC (/showthread.php?tid=65577) Pages:
1
2
|
HOW TO FORCE FILE DOWNLOD TO PC - kwangu - 06-27-2016 Its been months now wrestling with download file in CI. When i try an example from documentation it works since its static but when i make it dynamic it doesn't work. Please take a look at this code and suggest the problem http://pastebin.com/0jL4dj90 RE: HOW TO FORCE FILE DOWNLOD TO PC - PaulD - 06-27-2016 "it doesn't work" does not give us much to go on. What did you expect and what did you get? RE: HOW TO FORCE FILE DOWNLOD TO PC - kwangu - 06-29-2016 (06-27-2016, 04:26 PM)PaulD Wrote: "it doesn't work" does not give us much to go on. What did you expect and what did you get? Did you see the code by following the link i have given? I expect the file should be downloaded from the server to visitor's computer of which is not happening now. RE: HOW TO FORCE FILE DOWNLOD TO PC - PaulD - 06-29-2016 Well there could be a whole host of reasons. The main one is usually the file path. Try echoing out your filepath and filename and see if it is what you were expecting. I believe file_get_contents requires the full server path or a URL, not a relative path. PS you may also want to add a check into your method that file_get_contents actually worked, and if not produce an error message. RE: HOW TO FORCE FILE DOWNLOD TO PC - InsiteFX - 06-29-2016 Try this and see if it works for you. PHP Code: $path = '/uploads/docs/'.$name; // set the file path null - will read the contents from the path true - will force the mime type to the filename RE: HOW TO FORCE FILE DOWNLOD TO PC - kwangu - 07-01-2016 It seems "file_get_contents" has got a problem. So instead i tried this $path = base_url('uploads/docs/'.$name); // Read the file's contents The file is being downloaded to the pc properly but when i try to open it, its not opening. It becomes a corrupted file. Why is this so and what could be the solution RE: HOW TO FORCE FILE DOWNLOD TO PC - Wouter60 - 07-02-2016 When downloading files, never refer to a url, but always to a path, relative to the folder where your index.php is. The reason why the file seems to be downloaded, is that CI thinks it's a new file. So, it will download it, but the file won't have any content. RE: HOW TO FORCE FILE DOWNLOD TO PC - kwangu - 07-02-2016 (07-02-2016, 05:34 AM)Wouter60 Wrote: When downloading files, never refer to a url, but always to a path, relative to the folder where your index.php is. may you provide an example please..am stuck RE: HOW TO FORCE FILE DOWNLOD TO PC - Wouter60 - 07-02-2016 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); Now, in the controller method, I decode the given filename. PHP Code: public function download_file($name) RE: HOW TO FORCE FILE DOWNLOD TO PC - Paradinight - 07-03-2016 (07-01-2016, 03:37 PM)kwangu Wrote: It seems "file_get_contents" has got a problem. So instead i tried this Read the file with a text editor. |