Jump to content

Recommended Posts

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***

Link to comment
https://forums.phpfreaks.com/topic/198558-shell-exec-problems/
Share on other sites

Executing a command like that doesn't fork it into the background so your PHP script is not finishing before the PDF has a chance to generate.  In fact PHP will wait for the command to finish before resuming execution.

 

My guess is rml2pdf is not in your system's PATH variable so when you execute the command it fails with command not found.  Or it is possible that $filename is a relative path and the PDF is generated but it's not where you expected it to be.

 

Link to comment
https://forums.phpfreaks.com/topic/198558-shell-exec-problems/#findComment-1041946
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.