Search code examples
phpexecunoconv

run exec in php for converting file using unoconv


I'm trying to convert HTML file into RTF file using unoconv in php.

From php I'm calling :


    ......
    file_put_contents("/tmp/unoconv55b2862fea753.html", $content);
    $command = "unoconv -f rtf -o /tmp/unoconv55b2862fea753.rtf /tmp/unoconv55b2862fea753.html";
    exec($command, $output);
    $converted = file_get_contents("/tmp/unoconv55b2862fea753.rtf");

the problem is, that file_put content will save .html, but unoconv for some reason doesn't save converted file into /tmp directory.

When I run that $command directly on server in console, converted file was created.

Do you have any idea where could be problem?


Solution

  • When configuring unoconv on ubuntu server to be run under apache (www-data) user This solution is based on:
    https://github.com/dagwieers/unoconv/issues/87#issuecomment-16563550
    and
    https://github.com/dagwieers/unoconv/issues/87#issuecomment-32084464

    Step-by-step guide
    Follow these steps:
    1. Create new file which will contain sudoers entry for user www-data: sudo vi /etc/sudoers.d/www-data
    2. Add following content to newly created file and save: www-data ALL=NOPASSWD: /usr/bin/unoconv
    3. In PHP exec() use "sudo unoconv"