Hi There, I have a problem with this piece of code and I'm hoping someone can help me.
The code actually does execute as I expect, the problem is with the line which executes a shell script. What it does is generate a PDF file on the server after calling that command which is a python script to generate PDFs. I then download the PDF from the server.
The problem is that the command takes more a few seconds to work, so it gets to the end before the PDF actually has time to generate and when I check the server the text file ($filename) is created but not the PDF. When I run the exact same command that is run in "$result = `rml2pdf $filename`;" it works just fine but just after a second. As you can see I thought trowing a pause in there would help that, but it didn't.
die($result) returns nothing.
Can anyone help?
***SNIP***
$fieldList = array('Telephone'=>array('Telephone','text'),
'Fax'=>array('Fax','text'),
'FName'=>array('Full Name','text'),
'Title'=>array('Title','text'),
'Email'=>array('Email','text'));
$pdfFileName = 'buscard'.$id.'.pdf';
$filename = 'temprml'.$id.'.rml';
if(isset($_POST['btnSubmit']))
{
foreach($fieldList as $k=>$v);{
$rml = str_replace("!".$k."!",$_POST[$k],$rml);
}
$oFile = fopen($filename,'w') or die("Can't open file");
fwrite($oFile, $rml);
fclose($oFile);
$result = `rml2pdf $filename`;
echo $result;
sleep(15);
$result = trim($result);
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=$pdfFileName");
header('Content-Transfer-Encoding: binary');
readfile($pdfFileName);
}
***SNIP***