简体   繁体   English

在php中运行exec以使用unoconv转换文件

[英]run exec in php for converting file using unoconv

I'm trying to convert HTML file into RTF file using unoconv in php. 我正在尝试在PHP中使用unoconv将HTML文件转换为RTF文件。

From php I'm calling : 从php我打电话:


    ......
    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. 问题是, file_put content将保存.html,但是由于某种原因unoconv不会将转换后的文件保存到/ tmp目录中。

When I run that $command directly on server in console, converted file was created. 当我直接在控制台中的服务器上运行该$ command时,已创建转换后的文件。

Do you have any idea where could be problem? 您知道哪里可能有问题吗?

The problem could lie with PHP not having the right privileges for the tmp directory. 问题可能出在PHP对tmp目录没有正确的权限。 Try saving the converted file to the root of your site (or a subfolder within it) and see if it converts successfully. 尝试将转换后的文件保存到站点的根目录(或其中的子文件夹),然后查看转换是否成功。

When configuring unoconv on ubuntu server to be run under apache (www-data) user This solution is based on: 在ubuntu服务器上配置unoconv以在apache(www-data)用户下运行时,此解决方案基于:
https://github.com/dagwieers/unoconv/issues/87#issuecomment-16563550 https://github.com/dagwieers/unoconv/issues/87#issuecomment-16563550
and
https://github.com/dagwieers/unoconv/issues/87#issuecomment-32084464 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 1.创建一个新文件,其中将包含用户www-data的sudoers条目:sudo vi /etc/sudoers.d/www-data
2. Add following content to newly created file and save: www-data ALL=NOPASSWD: /usr/bin/unoconv 2.将以下内容添加到新创建的文件中并保存:www-data ALL = NOPASSWD:/ usr / bin / unoconv
3. In PHP exec() use "sudo unoconv" 3.在PHP exec()中使用“ sudo unoconv”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM