Display PDF |
[eluser]sbarow[/eluser]
Hey, This is a really simple thing to do, but it seems in codeigniter is it s bit of a problem. I have a view that has a button to view an uploaded PDF, all I want is for the PDF to be opened and viewed like in normal HTML. The button (Link) sends the viewer to Code: base_url().site/pdf/12345_brochure.pdf How would I then get that PDF to display Code: function pdf($item) I have tried the above code but I get the following error fopen(images/image/453021504.brochure_test_.pdf) [function.fopen]: failed to open stream: No such file or directory I have also tried to with the base_url() included but does not help. Really appreciate any help. Thanks very much.
[eluser]plain jane[/eluser]
So get the PDF name from database and attach that to the path like Code: $item = $data[0]->pdf_name; this way it will display Code: <a href="<?php echo base_url(); ?>site/pdf/<?php echo $item; ?>" style="cursor:pointer">PDF</a> Thanks, ci user
[eluser]sbarow[/eluser]
Not having a problem getting the pdf from the database, having a problem actually displaying it. To clarify, viewing the pdf in a normal site you would create a link <a href="http://locahost/pdf/brochure.pdf" target="_blank">PDF</a> However in Codeigniter if you try do that the controller will look for a Class pdf and then a function brochure.pdf, obviously this is not what I want, I want it to just read the file. How would I go about that?
[eluser]plain jane[/eluser]
Do not give the controller and function path. Instead store the PDF out of the CI structure named in site_data folder and access the folder directly. Code: define('SITE_DATA', 'http://example.com/site_data/'); Code: <?php echo SITE_DATA;?>/pdf/<?php echo $item;?> May be you are missing base_url in your fopen() function Code: function pdf($item)
[eluser]InsiteFX[/eluser]
Code: header('Content-Length: '.filesize($path)); InsiteFX
[eluser]sbarow[/eluser]
Nope none of those suggestions work. InsiteFX I tried yours with readfile($path) and fopen($path) all it does is force the browser to download the file. All I want to be able to do is show/view/display the PDF in the browser. This simple thing is making me go insane.
[eluser]InsiteFX[/eluser]
Do you have a pdf file viewer installed in your browser? If not you need to install one. Like Adobe Reader. InsiteFX
[eluser]sbarow[/eluser]
Yip I do. Look this is the situation if I had to write an html website with a pdf in a folder then uploaded it to a server and went to view the file at say http://example.com/pdf_folder/brochure.pdf then the pdf would open in the normal PDF viewer for Safari, Chrome, Firefox etc. Thats all I want to be able to do but because codeigniter would read the "pdf_folder" as a function and "brochure.pdf" as a method obviously it does not display the file from the location http://example.com/pdf_folder/brochure.pdf |
Welcome Guest, Not a member yet? Register Sign In |