Search code examples
phppdf2swf

PDF2SWF: php exec() only works in terminal


Here is my code:

$pdf = '/Users/macbookpro/Desktop/q.pdf';
$swf = '/Users/macbookpro/Desktop/q.swf';

$command2 = 'pdf2swf -o '.$swf.' -T -z -t -f '.$pdf.' -s flashversion=9';
exec($command2,$out,$status);
var_dump($output);

The output is NULL and no SWF is generated. However, if I output the command and copy it to terminal, it works. How do I solve this?


Solution

  • exec runs as the user running the script. Apache user likely doesn't have the PATH variable telling it where to look for programs, so instead of

     $command2 = 'pdf2swf -o '.$swf.' -T -z -t -f '.$pdf.' -s flashversion=9';
    

    Try adding the location of pdf2swf, something like:

     $command2 = '/bin/pdf2swf -o '.$swf.' -T -z -t -f '.$pdf.' -s flashversion=9';
    

    And make sure that the apache user has permission to get to the executable, and permission to execute it.

     chmod a+x /bin/pdf2swf
    

    Of course replace /bin/ with where ever pdf2swf really lives for all the example code in this answer.