php - 如何使用 Php 执行 docx2txt shell 脚本?

标签 php shell terminal docx

我正在使用 docx2txt 提取 .docx 内容。 我可以通过在终端中运行 shell 脚本来实现这一点。

下面是终端 shell 脚本,

 niveus@niveus:/var/www/docx2txt$ ./docx2txt.sh test.docx

 Text extracted from <test.docx> is available in <test.txt>.

但我也想用 php 运行这个脚本。

我试过这个,

<?php

 $docxFilePath = "test.docx";
 echo  $content = shell_exec('./docx2txt.sh '.escapeshellarg($docxFilePath));

?>

输出 无法从中提取文本!

(docx2txt.shtest.txt 均位于同一文件夹 docx2txt 中)

最佳答案

问题在于权限。将 docx2txt 文件夹的权限更改为 chmod 777 后 以下 php 代码有效。

<?php

 $docxFilePath = "test.docx";
 echo  $content = shell_exec('./docx2txt.sh '.escapeshellarg($docxFilePath));

?>

关于php - 如何使用 Php 执行 docx2txt shell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31182870/

相关文章:

php - 网站上的 Paypal 整合

php - 如何更新 MySQL 两列查找表,其中每个字段都是主键

linux - 初始化脚本 '/dev/tty: No such device or address' 重定向错误

linux - bash脚本: how to pass arguments to a function of a running script from another one?

linux - 如何将 bash 命令的日志放在变量中?

linux - 如何在终端上使用 VIM 配色方案?

php - Laravel - 过去 7 天的查询计数值

php - 命令行 PHP mysql_connect() 错误

php - ffmpeg:在 php 中以原始方向生成视频的缩略图

json - 在 shell 脚本中解码 JSON 和 base64 编码值