![]() |
Download function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Download function (/showthread.php?tid=57614) |
Download function - El Forum - 03-27-2013 [eluser]jadine[/eluser] Hi, I would really appreciate if someone can give a few pointers here. I have in my controller a download function which looks like this: Code: public function download($file_name){ In my view, I have: Code: echo anchor('gis/download/'.$result, 'Download KMZ file', 'title="KMZ File"'); $result is the file name passed from the controller. The generated URL of the link looks like: http://{Domain}/trackdb/index.php/gis/download/Sites.kmz Which is the correct file name. The problem is that the file doesn't actually download. It simply downloads a dummy 1 KB .kmz file (the real file in that location is over 2MB). Many thanks Jad Download function - El Forum - 03-27-2013 [eluser]jadine[/eluser] I've tried using the download helper instead. The message I kept getting is: Message: file_get_contents(path...) [function.file-get-contents]: failed to open stream: No such file or directory The problem is that I've tried everything with path, writing it as a relative path, absolute path...etc. and I still keep getting the message. Code: public function download($file_name){ Download function - El Forum - 03-27-2013 [eluser]jadine[/eluser] Solved. Path has to be specified relative to index.php file, not the controller. Download function - El Forum - 03-27-2013 [eluser]TheFuzzy0ne[/eluser] Welcome to the CodeIgniter forums! I'm glad you solved your problem. It's a good idea to always use absolute paths wherever possible. There are some built-in constants to help with that. Code: BASEPATH // The path to the ./system directory. |