使用 shell_exec() 执行 libreoffice 命令时出错

Error on executing libreoffice command using shell_exec()

代码:

shell_exec('libreoffice --convert-to pdf `'.$my_file.'` --headless');

我也试过了

shell_exec('libreoffice --convert-to pdf `'.$my_file'` --headless > /dev/null');

执行上述操作时服务器出错:

Output:sh: /my_files/my_file.doc: cannot execute binary file

注意: linux 的所有其他命令与 shell_exec() 一起工作正常,只是 libreoffice 命令不起作用。在 linux 终端上,libreoffice 命令工作正常,只是无法使用 PHP.

您正在使用反引号,它告诉子 shell 运行 该命令并在其位置使用其输出。改用双引号,它会更频繁地工作。