CodeIgniter Forums
linking to .pdf - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: linking to .pdf (/thread-40357.html)

linking to .pdf - El Forum - 04-06-2011

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

I think I am getting a little closer.

Instead of doing this in my controller:
I want to do something like this:
and store the .pdf in the view folder.

Or am I barking up the wrong tree?

linking to .pdf - El Forum - 04-06-2011


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

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

This is the key:
header("Content-Type: application/octet-stream");
Content-type application/x-pdf-document or application/pdf is sent while sending PDF file. Adobe Reader usually sets the handler for this MIME type so browser will pass the document to Adobe Reader when any of PDF MIME types is received.


linking to .pdf - El Forum - 04-07-2011

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

Depending on what hosting environment you have the .htaccess file looks
different. A .htaccess file for a CI installation COULD look like this:
RewriteEngine On
RewriteCond $1 !^(index\.php|flash|images|stylesheets|javascript|pdf_files|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

linking to .pdf - El Forum - 04-07-2011

Thank you, header and .htaccess were the keys.