Jump to content

show pdf - newbie


sturobinson81

Recommended Posts

Hi,

 

newbie programmer here.

 

Trying to get the following code working, but i keep getting an error.

Probably something stupid, or maybe just my lack of knowledge :)

can post error message if it would help. Any help very much appreciated :)

 

 

<?php
include 'connect.php';
$result = mysqli_query($con,"SELECT * FROM pdfs
WHERE Keywords LIKE '%stu%'");
 
 
while($row = mysqli_fetch_array($result))
  {
  $pdf=$row['FILENAME'];
  echo $row['Keywords'];
  echo "<br>";
  echo $row['FILENAME'];
  echo "<br>";
  
  header("Content-type: application/pdf");
  header("Content-Disposition: inline; filename=$pdf");
  readfile($pdf);
  
  }
 
mysqli_close($con);
?> 
 
 
 
 
 
 
 

 

Link to comment
https://forums.phpfreaks.com/topic/286857-show-pdf-newbie/
Share on other sites

Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 15


 


Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 16


stu test2


newsite/pdfs/test2.pdf


 


Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 15


 


Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:13) in /home/bictech/public_html/newsite/search2.php on line 16

Link to comment
https://forums.phpfreaks.com/topic/286857-show-pdf-newbie/#findComment-1472033
Share on other sites

I still get the following errors...

 

Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:12) in /home/bictech/public_html/newsite/search2.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at /home/bictech/public_html/newsite/connect.php:12) in /home/bictech/public_html/newsite/search2.php on line 9

%PDF-1.3 %âãÏÓ 4 0 obj << /Type /Page /Parent 2 0 R /Contents 10 0 R /MediaBox [0.0000 0.0000 1190.5512 841.8898] /TrimBox [0.0000 0.0000 1190.5512 841.8898] /CropBox [0.0000 0.0000 1190.5512 841.8898] /Resources << /ProcSet [/PDF /ImageC /Text /ImageB] /XObject << /Im12 12 0 R /Im49 49 0 R /Im50 50 0 R /Im70 70 0 R /Im71 71 0 R >> /Font << /F13 13 0 R /F17 17 0 R /F21 21 0 R /F25 25 0 R /F30 30 0 R /F34 34 0 R /F38 38 0 R /Symb 43 0 R /F51 51 0 R /F55 55 0 R /F60 60 0 R /F65 65 0 R /F72 72 0 R >> /ExtGState << /GS11 11 0 R >> /ColorSpace << /CS48 48 0 R >> >> >> endobj 10 0 obj << /Filter [/FlateDecode ] /Length 4415 >> stream xÚÕ[É’7z¾3‚ݢØ9Ø^lRÉ´G#zØÖÅò!»*»+GU•ÅZšn=ˆŸÃ‡ŸÀbŸýþ²è¬^bd˜¡(d&ðã_¿)VQÿ‡Ðâ¿,ûÿôŸÙêù³ßýð1r½{þìãógšºJSFå Œ•LrrÎd%8wá/Bª°Í»ãäm÷üÙ?Ž÷ÄçÚQòëógþS.ðŽUÑœ`

 

and a lot more garbage...

 

anything im doing obviously wrong?

Link to comment
https://forums.phpfreaks.com/topic/286857-show-pdf-newbie/#findComment-1472087
Share on other sites

my current code

------------------------------------------------

 

------------------------connect.php--------------------------

<?php
// Create connection
$con=mysqli_connect("bictechnology.co.uk","bictech_stu","bictech2014","bictech_pdfdb");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL:" . mysqli_connect_error();
  exit();
  }
?>

---------------------------------------------------

 

 

---------------------search2.php----------------------

<?php
include 'connect.php';
$result = mysqli_query($con,"SELECT * FROM pdfs
WHERE Keywords LIKE '%stu%'");
while($row = mysqli_fetch_array($result))
  {
 $pdf=$row['FILENAME']; 
  header("Content-type: application/pdf");
  header("Content-Disposition: inline; filename=$pdf");
  readfile($pdf);
  }
mysqli_close($con);
?>
--------------------------------------------------------------------------

Link to comment
https://forums.phpfreaks.com/topic/286857-show-pdf-newbie/#findComment-1472088
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.