Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch unoconv from php file

I want to launch the command "unoconv" from a script php.

$command = '/usr/bin/unoconv --server localhost --port 2002 --format=pdf file.rtf >/dev/null 2>/dev/null';
$rc = system( $command );
echo $rc;

The command return no result and the file is not created.

I think is a problem from access with www-data and unoconv.

When I'm launching the command in shell, the file is created.

Any idea?

like image 327
jeremy.romano Avatar asked Jul 11 '12 07:07

jeremy.romano


2 Answers

You can add command unoconv to sudoers. I do this in this way:

I create wrapper bash script in for example /usr/local/bin where I have command unoconv.

#!/bin/bash

if [ -z "$1" ]; then
    echo "Must pass file";
    exit 10;
fi

/usr/bin/unoconv -f pdf $1.rtf

after this I adding entry in /etc/sudoers.d:

www-data    ALL=NOPASSWD: /usr/local/bin/unoconv.sh

And now you can call script in php:

exec('sudo /usr/local/bin/unoconv.sh '.$fileName);
like image 62
Piotr Olaszewski Avatar answered Oct 01 '22 02:10

Piotr Olaszewski


Try to run

$output = `/usr/bin/unoconv --server localhost --port 2002 --format=pdf file.rtf`;

instead and see error messages.

like image 22
Igor Chubin Avatar answered Oct 01 '22 04:10

Igor Chubin