Hi, my name is Thiago and I’m from Brazil. I’m trying to open a existent pdf file into a browser using CI but I had no success. Someone can help me?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
February 11, 2009 1:04pm
Subscribe [3]#1 / Feb 11, 2009 1:04pm
Hi, my name is Thiago and I’m from Brazil. I’m trying to open a existent pdf file into a browser using CI but I had no success. Someone can help me?
#2 / Feb 11, 2009 3:01pm
It’s just an ordinary ‘a href=...’. I don’t think CI has anything to do with the opening, that is dependent on how the browser is setup to handle links of that type.
But maybe you can explain in a little more detail what you are trying to accomplish?
#3 / Feb 11, 2009 3:16pm
Make sure in your htaccess file that the directory or file is excluded from being routed through codeigniters routing. Edit your htaccess file.
#4 / Feb 11, 2009 3:36pm
I am trying to open a view of the IC and putting href not just open the pdf file. I tried to upload through the controller, but without success.
This is an excerpt of the code view:
<table width=“588” height=“313” border=“0” align=“center” cellpadding=“0” cellspacing=“0”>
<tr>
<td height=“215”>
_ - Some Text Here_ <font color=”#ff0000”> </font>_
</td>
</tr>
</table>
And once again, I tried to construct a function trough and into this function, I tried to load pdf file but no success.
#5 / Feb 11, 2009 8:49pm
just like hostcord said, you may exclude path to pdf file for being route by CI in .htaccess
RewriteCond $1 !^(index\.php|pathtopdf)
#6 / Feb 12, 2009 8:24am
Adi, I tried to do what you and hostcord said but I have no success.
Something that I tried was call a function of controller in href into the view and in the controller call $this->load->view(‘subfolder/file.pdf’);
but this way appeared a error like this:
Warning: Unexpected character in input: ‘’ (ASCII=1) state=1 in C:\ complete path on line 394
Parse error: syntax error, unexpected ‘:’ in C:\ complete path on line 394
I don’t understand this error because, the pdf file is like any pdf file that can be found on internet
#7 / Feb 12, 2009 9:25am
not sure what you want, why you load pdf file as view file? could you explain what exactly do you want?
if you want to force user to download pdf file, you can use download helper
$this->load->helper('download');
$data = file_get_contents("subfolder/file.pdf");
$name = 'file.pdf';
force_download($name, $data);#8 / Feb 12, 2009 9:41am
let me explain a little in details:
I have a menu where the stories are posted and some news may be a pdf file that is in a subdirectory.
Then I want to create a link to open the pdf file in web page using the CI.
#9 / Feb 12, 2009 9:52am
then it’s just as easy as create html link news in pdf
#10 / Feb 12, 2009 11:01am
this is the exact problem, this does not work
#11 / Feb 12, 2009 11:04am
any error message ? try to open http://yourdomain.cnom/path/to/file.pdf in your browser
#12 / Feb 12, 2009 11:09am
I’m using the Vertrigo, doing what you said http://yourdomain.cnom/path/to/file.pdf in my browser, the request goes to the index.php of Vertrigo Serv.
#13 / Feb 12, 2009 11:43am
no message errors, just browser not found the page requested
#14 / Feb 12, 2009 1:38pm
Solved the problem. I put the subfolder where the pdf file on the same level of the CI system folder and again tried to use that Adi Setiawan said:
$ this-> load-> helper ( ‘download’);
$ data = file_get_contents ( “subfolder / file.pdf”);
$ name = ‘file.pdf’;
force_download ($ name, $ date);
And it worked, now I can load through a view open a pdf file.
#15 / Feb 12, 2009 1:40pm
Thanks Adi, hostcord and jalalski.