linking to .pdf - 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: linking to .pdf (/showthread.php?tid=40357) |
linking to .pdf - El Forum - 04-06-2011 [eluser]miramichi[/eluser] I have inherited the job of maintaining a site built with code igniter. So far so good. But I can't figure out how to get a link to work to a .pdf (404 Page Not Found). The .pdf file is in the same directory as the index file. The controller and page works fine, but the link goes nowhere. At the moment I have an absolute path to the .pdf Thanks for your help. linking to .pdf - El Forum - 04-06-2011 [eluser]miramichi[/eluser] I think I am getting a little closer. Instead of doing this in my controller: Code: $this->load->view('contract') Code: $this->load->view('contract.pdf') Or am I barking up the wrong tree? linking to .pdf - El Forum - 04-06-2011 [eluser]LuckyFella73[/eluser] Code: $this->load->view('your_file') is used to load HTML/ PHP files. A PDF files is nothing your browser can render like HTML - so that is not the way to go. You can set a link to your .pdf file in your html code and when clicking the pdf should open in your browser displayed by the acrobat plugin. If you still get a 404 page you have to adjust your htaccess file for you needs. I would prefer to place the pdf file in seperated directory and not at the root level. linking to .pdf - El Forum - 04-06-2011 [eluser]miramichi[/eluser] I have placed my .pdfs in a folder at the root level, but still get a 404. Should I out the htaccess in that folder? Can you give an example of an htaccess that will allow the pdfs to be viewed? linking to .pdf - El Forum - 04-07-2011 [eluser]InsiteFX[/eluser] This is the key: Code: header("Content-Type: application/octet-stream"); InsiteFX linking to .pdf - El Forum - 04-07-2011 [eluser]LuckyFella73[/eluser] Is it common praxis to load .pdf files like every other view (sending the right header) instead of just linking to the file? Doesn't make much sense to me unless you generate the pdf file dynamicly maybe. But maybe I'm wrong. @miramichi Depending on what hosting environment you have the .htaccess file looks different. A .htaccess file for a CI installation COULD look like this: Code: RewriteEngine On linking to .pdf - El Forum - 04-07-2011 [eluser]miramichi[/eluser] Thank you, header and .htaccess were the keys. |