0

Using the above technologies, I want to create a PDF, store it in my db, and email it. All with the click of one button.

I also want to call it up and have it be able to display with a hyperlink.

I am very new to FPDF. Therefore, I am trying to start off very slowly.

I began with this link stackoverflow Q

I put both parts of his code into the same page and also tried with separate pages. I made the suggested changes/additions and even did a line by line comparison.

I still get the message, "format error: not a PDF or corrupted"

If I just

$pdf->Output();

I get the pdf to display. It's either the way the string is being Output, or it's the header() function. It's not the storage method, unless my column setup is incorrect. BUt a blob is a blob, right?

here's the code where I enter it in:

<?php
session_start();
include "server.php";//my file to connect to db
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');

$content = $pdf->Output("", "S"); //return the pdf file content as string

$sql = "update table set table_pdf= '".addslashes($content)."' " . 
    "where table_id = '188'";

mysql_query($sql);

//here's where I retrieve it

$sql2 = "select table_pdf from table where table_id = '188'"; 
$result2 = mysql_query($sql2); 
$rs = mysql_fetch_assoc($result2); 

$content2 = $rs['rdngs_hdr_pdf']; 
header('Content-Type: application/pdf'); 
header("Content-Length: ".strlen(content2)); 
header('Content-Disposition: attachment; filename=myfile.pdf'); 
print $content2; 
?>

I've also tried this...from another source. I still get the same error message.

$content = $pdf->Output("", "S"); //return the pdf file content as string
$data = unpack("H*hex", $content);

$sql = "update table set table_pdf= " . 0x".$data['hex']." . " " . 
    "where table_id = '188'";

The $sql from above gives a parse error, so I tried to fix it by adding " in between . & 0. It doesn't seem right, nor does it fix the problem.

Like I said, I have tried the other ideas on the other question link above. right now it just sits on the version where the addslashes is there.

I would appreciate anyone who answers this thread and follows it as I will attempt your solutions promptly and let you know if it worked. Thank you in advance.

3
Contributors
4
Replies
15
Views
7 Years
Discussion Span
Last Post by red_ruewei
0

mmm...i also try same thing.i had successful store it in db as blob type,but having problem to view it...

here my code

global $strDesc;
		$max_size = 1000000000;
		$fileUpload1 = $HTTP_POST_FILES['fileUpload1']['tmp_name'] ;
		if($fileUpload1 != NULL)
		{
			  $fileUpload_name=$HTTP_POST_FILES['fileUpload1']['name'];
			  $fileUpload_size=$HTTP_POST_FILES['fileUpload1']['size'];
			  $fileUpload_type=$HTTP_POST_FILES['fileUpload1']['type'];
			
			  $fileHandle=fopen($fileUpload1, "rb");
			  $fileContent=fread($fileHandle,filesize($fileUpload1));
			  $fileContent=addslashes($fileContent);
			  fclose($fileHandle);
			
			  $sqls = "INSERT INTO table(file_content,file_type) VALUES 
                 ('$fileContent','$fileUpload_type')";    
				
		}
0

Did you see teh info about MEDUIMBLOB vs. BLOB and teh escape string.
Those 2 items fixed the fpdf corrunption issue in that post.

0

Did you see teh info about MEDUIMBLOB vs. BLOB and teh escape string.
Those 2 items fixed the fpdf corrunption issue in that post.

thanks for responds.will look it now

0

Using the above technologies, I want to create a PDF, store it in my db, and email it. All with the click of one button.

I also want to call it up and have it be able to display with a hyperlink.

I am very new to FPDF. Therefore, I am trying to start off very slowly.

I began with this link stackoverflow Q

I put both parts of his code into the same page and also tried with separate pages. I made the suggested changes/additions and even did a line by line comparison.

I still get the message, "format error: not a PDF or corrupted"

If I just

$pdf->Output();

I get the pdf to display. It's either the way the string is being Output, or it's the header() function. It's not the storage method, unless my column setup is incorrect. BUt a blob is a blob, right?

here's the code where I enter it in:

<?php
session_start();
include "server.php";//my file to connect to db
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');

$content = $pdf->Output("", "S"); //return the pdf file content as string

$sql = "update table set table_pdf= '".addslashes($content)."' " . 
    "where table_id = '188'";

mysql_query($sql);

//here's where I retrieve it

$sql2 = "select table_pdf from table where table_id = '188'"; 
$result2 = mysql_query($sql2); 
$rs = mysql_fetch_assoc($result2); 

$content2 = $rs['rdngs_hdr_pdf']; 
header('Content-Type: application/pdf'); 
header("Content-Length: ".strlen(content2)); 
header('Content-Disposition: attachment; filename=myfile.pdf'); 
print $content2; 
?>

I've also tried this...from another source. I still get the same error message.

$content = $pdf->Output("", "S"); //return the pdf file content as string
$data = unpack("H*hex", $content);

$sql = "update table set table_pdf= " . 0x".$data['hex']." . " " . 
    "where table_id = '188'";

The $sql from above gives a parse error, so I tried to fix it by adding " in between . & 0. It doesn't seem right, nor does it fix the problem.

Like I said, I have tried the other ideas on the other question link above. right now it just sits on the version where the addslashes is there.

I would appreciate anyone who answers this thread and follows it as I will attempt your solutions promptly and let you know if it worked. Thank you in advance.

hi,
i had successful done it.i manage save pdf on db as blob type and view it.but my way is diff abit coz is store pdf file that exist/upload by user from their computer and view it.
and i'm not using FPDF.

here is my sampel

to store on DB
[add_pdf.php]

global $strDesc;
   
      $max_size = 1000000000;
   
      $fileUpload1 = $HTTP_POST_FILES['field_name_to_upload_file']['tmp_name'] ;
   
      if($fileUpload1 != NULL)
   
      {
   
      $fileUpload_name=$HTTP_POST_FILES['field_name_to_upload_file']['name'];
   
      $fileUpload_size=$HTTP_POST_FILES['field_name_to_upload_file']['size'];
   
      $fileUpload_type=$HTTP_POST_FILES['field_name_to_upload_file']['type'];
  
      
  
      $fileHandle=fopen($field_name_to_upload_file, "rb");
  
      $fileContent=fread($fileHandle,filesize($field_name_to_upload_file));
  
      $fileContent=addslashes($fileContent);
  
      fclose($fileHandle);
  
       
  
      $sqls = "INSERT INTO table(file_content,file_type) VALUES
  
      ('$fileContent','$fileUpload_type')";
  
       
  
      }

here code to call view_pdf page

create button

<input name="submit" type="submit" id="submit" value="View PDF FILE"  onclick="javascript:Popup('view_pdf.php')" />

action for button

if($submit == 'View PDF FILE')
{
	echo '<script type="text/javascript">';
	echo 'window.open("view_pdf.php");';//it will open new window
	echo '</script>';
		
}

here code to view the pdf file that store as blob
[view_pdf.php]

$dbQuery = "SELECT file_content,file_type FROM table where bil  = '$bil'  ";
   
$result = @mysql_query($dbQuery) or die(mysql_error()); 
 
$fileType = @mysql_result($result, 0, "file_type");
$fileContent = @mysql_result($result, 0, "file_content"); 
header("Content-type: $fileType"); 

echo $fileContent; 

?>

hope this helps;)

Edited by red_ruewei: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.