The page that runs to create the pdf from a template is :
Code: Select all
<?php
set_time_limit( 180 ); // this script can be very slow
//create short variable names
$number = $_GET['orderno'];
function pdf_replace( $pattern, $replacement, $string )
{
$len = strlen( $pattern );
$regexp = '';
for ( $i = 0; $i<$len; $i++ )
{
$regexp .= $pattern[$i];
if ($i<$len-1)
$regexp .= "(\)\-{0,1}[0-9]*\(){0,1}";
}
return ereg_replace ( $regexp, $replacement, $string );
}
if(!$number)
{
echo '<h1>Error:</h1>This page was called incorrectly';
}
else
{
//generate the headers to help a browser choose the correct application
header( 'Content-Disposition: filename=test.pdf');
header( 'Content-type: application/pdf' );
$date = date( 'F d, Y' );
// open our template file
$filename = 'test.pdf';
$fp = fopen ( $filename, 'r' );
//read our template into a variable
$output = fread( $fp, filesize( $filename ) );
fclose ( $fp );
// replace the place holders in the template with our data
$output = pdf_replace( '<<NUMBER>>', $number , $output );
// $output = pdf_replace( '<<cat>>', $prods, $output );
// $output = pdf_replace( '<<mm/dd/yyyy>>', $date, $output );
// send the generated document to the browser
echo $output;
}
?>QUOTE: <<NUMBER>>
As i have only the one line to test the basic placeholder replacement. At present i'm getting an error saying the file is damaged. If i remove the line calling in the function to replce the placeholder with the data, the page opens, though obviously with the placeholder still there. So it seems to be the replacement function thats causing the errors. Anyone any idea?