Hello,
I am creating a pdf document and outputting it as a string using:
$mypdf = $pdf-%26gt;Output('', 'S');
I am then putting it into a database as a BLOB and redirecting to page y using:
$insertSQL = sprintf(''INSERT INTO PDF_file (pdf_name) VALUES (%s)'',
?GetSQLValueString($mypdf, ''text''));
mysql_select_db($database_files, $files);
$Result1 = mysql_query($insertSQL, $files) or die(mysql_error());
I have a link on page y called:
%26lt;a href=''home.php?pdf_id=%26lt;?php echo $row_getPDF['pdf_id'];?%26gt;''%26gt;Click here to view your PDF.%26lt;/a%26gt;
When whoever clicks the link, the following is processed:
if (isset($_GET['pdf_id'])) {
header(''Content-type: application/pdf'');
header('Content-disposition: attachment; filename=''myresume.pdf''');
echo $row_getPDF['pdf_name'];
}
A box opens and I am giving the option to open or save the file. The pdf downloads but when I try to view it there is a couple lines present on the second page and that's it. The pdf is either not being stored properly or not downloaded properly. It works just fine when I am not converting it into a string. Any help is appreciated.
Thanks,
Kelsey
Problem opening PDF after creating it... It works just fine when I am not converting it into a string. Problem opening PDF after creating it...
The reason I am storing it in the database is because the pdf file being created needs to be sent to multiple users if needed and viewed by multiple users. Or is there a way to do this without storing it locally on a computer??I have done more looking into the problem though and it seems like there is an issue in storing the string in the database and retrieving it. So what I have done is the following:
//create pdf, convert to string, assign it to a variable, and get pdf name from form
$pdf_content = $pdf-%26gt;Output('$pdf', 'S');
$fileName = $_POST['pdf_name'];
$fileName .= '.pdf';
//insert into database
$insertSQL = sprintf(''INSERT INTO my_table (pdf_name, pdf_content) VALUES (%s, %s)'',
GetSQLValueString($fileName, ''text''),
GetSQLValueString($pdf_content, ''text''));
?mysql_select_db($database_mydatabase, $mydatabase);
?$Result1 = mysql_query($insertSQL, $mydatabase) or die(mysql_error());
?$insertGoTo = ''/view/pdf.php'';
?if (isset($_SERVER['QUERY_STRING'])) {
?$insertGoTo .= (strpos($insertGoTo, '?')) ? ''%26amp;'' : ''?'';
?$insertGoTo .= $_SERVER['QUERY_STRING'];
?}
?header(sprintf(''Location: %s'', $insertGoTo));
Then on the page ''pdf.php'' I have a link to click on the pdf:
%26lt;a href=''home.php?pdf_id=%26lt;?php echo $row_getPDF['pdf_id'];?%26gt;''%26gt;%26lt;?php echo $row_getPDF['pdf_name'];?%26gt;%26lt;/a%26gt;
After creating the url I have:
if (isset($_GET['pdf_id'])) {
?$fileType = 'application/pdf';
?header(''Content-type: ''.$fileType.''; charset=UTF-8'');
?header(''Content-disposition: attachment; filename=''.$row_getPDF['pdf_name']);
?echo $row_getPDF['pdf_content'];
}
When I open the pdf, the pdf is corrupted and only a couple lines of the original pdf work. I have tried using?''$_SESSION['pdf_content'] = $pdf-%26gt;Output('$pdf', 'S');'' and replacing ''echo $row_getPDF['pdf_content'];'' with?''echo $_SESSION['pdf_content'];'' and it works just fine. So what am I doing wrong when storing it in the database? The ''pdf_content'' column is set to MEDIUMBLOB.
I just got it working. I was missing the function addslashes() on the pdf string. The tutorial I was following wasn't using it. Thanks anyways for the help.