Welcome Guest, Not a member yet? Register   Sign In
Display PDF
#1

[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
With pdf being the function and 12345_brochure.pdf being the method. This method is pulled from a database so it will be different when a new brochure is uploaded by the client.

How would I then get that PDF to display
Code:
function pdf($item)
    {
    
        fopen("images/image/$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.
#2

[eluser]plain jane[/eluser]
Do you store the PDF name in database?
#3

[eluser]sbarow[/eluser]
Yeah just the pdf name. File is stored in a folder.
#4

[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="&lt;?php echo base_url(); ?&gt;site/pdf/&lt;?php echo $item; ?&gt;" style="cursor:pointer">PDF</a>

Thanks,
ci user
#5

[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?
#6

[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:
&lt;?php echo SITE_DATA;?&gt;/pdf/&lt;?php echo $item;?&gt;


May be you are missing base_url in your fopen() function
Code:
function pdf($item)
    {
    
        fopen("base_url()/images/image/$item", "");

    }
#7

[eluser]InsiteFX[/eluser]
Code:
header('Content-Length: '.filesize($path));
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=$file");
readfile($path);

InsiteFX
#8

[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.
#9

[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
#10

[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




Theme © iAndrew 2016 - Forum software by © MyBB