unoconv使用www数据从终端工作,但不作为www数据从php脚本工作

unoconv使用www数据从终端工作,但不作为www数据从php脚本工作,php,shell,pdf,ubuntu,uno,Php,Shell,Pdf,Ubuntu,Uno,我用php编写了以下函数 public static function convert($originFilePath, $outputDirPath, $toFormat) { $command = 'echo $PATH & UNO_PATH=/usr/lib/libreoffice unoconv --format %s --output %s %s'; $command = sprintf($command, $toFormat, $outputDirPath,

我用php编写了以下函数

public static function convert($originFilePath, $outputDirPath, $toFormat)
{
    $command = 'echo $PATH & UNO_PATH=/usr/lib/libreoffice unoconv --format %s --output %s %s';
    $command = sprintf($command, $toFormat, $outputDirPath, $originFilePath);
    exec($command, $output, $result_var);

    return compact('output', 'result_var', 'outputDirPath', 'originFilePath', 'toFormat');
}
它没有生成任何错误消息,也没有生成任何pdf文件

在终端中,当我以www数据的形式直接运行unoconv时,我没有任何问题

这是我执行后的结果:

2013-05-26 03:05:30 Error: Array
(
    [output] => Array
        (
            [0] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        )

    [result_var] => 1
    [outputDirPath] => /var/virtual/storyzer.com/cake-json/ltequotationapp/webroot/outputfiles/Excel/2
    [originFilePath] => /var/virtual/storyzer.com/cake-json/ltequotationapp/webroot/outputfiles/Excel/2/dsadas.xlsx
    [toFormat] => pdf
)

请告知。

有关可能的解决方案,请参阅

摘自

这就是我通过运行在Cent OS 6.2(unoconv版本0.6和LibreOffice 3.4.5.2)上的apache/php代码使unoconv工作的原因: (这只是一个解决办法-我不知道根本原因)

将apache用户从/sbin/nologin更改为/bin/bash(这在/etc/passwd文件中完成) 添加新用户unoconv 添加了一个新文件/etc/sudoers.d/unoconv,其中包含以下内容:

apache ALL=(unoconv)NOPASSWD:/usr/bin/unoconv (请注意,我的unoconv程序位于此位置/usr/bin/unoconv-您可以使用哪个unoconv找到它)

使用visudo注释掉以下行(在行首添加#)

#默认要求

重新启动sshd和httpd服务

使用php exec()函数像这样运行unoconv(需要更改输入文件名和输出目录):

exec('sudo-u unoconv/usr/bin/unoconv-f pdf-o bankgenerated Teacher_bulk_upload.csv')


希望这对您有用

问题是我正在使用Nginx和PHP-FPM

在Nginx中,默认情况下不声明路径

因此有两种解决方案

1) 您可以在Nginx的fastcgi参数中声明它

2) 在运行
unoconv
代码之前,在脚本中使用
putenv()
声明它

putenv('PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/node/bin')


我还想补充一点,某种故障排除方法帮助我认识到了这个问题。看。

我以前在谷歌搜索时看到过这个。在我想尝试这个解决方法之前,我正在尝试其他可能的解决方案。我将等待其他可能的解决办法。如果没有好结果,我会采取这种变通办法。谢谢~我花了一个多星期的时间,但我终于找到了答案!:)互联网太棒了~~