我有一个shell脚本,它使用unoconv,然后是pdftk。当我通过命令行运行脚本时,它的工作原理就是我想要的。当我在php中使用shell_exec($cmd)
时,它使用相同的确切命令运行脚本(我知道是因为脚本中有回显),但它看起来像不使用unoconv(因此不能使用pdftk)。任何想法如何解决这个问题?这里的一些代码:shell脚本完全在终端中运行,但不能在运行时运行php
if(isset($_FILES["file"]["name"]) && !empty($_FILES["file"]["name"])){
$fname = $_FILES["file"]["name"];
$tmp_name = $_FILES["file"]["tmp_name"];
$dir = "powerpoints/".$name."/";
$ispdf = "1";
$output = shell_exec('mkdir '.$dir);
chmod($dir, 0777);
echo $output;
if(move_uploaded_file($tmp_name, $dir.$fname)){
chmod($dir.$fname, 0777);
$cmd = 'importppt.sh '.$name.' '.str_replace(".ppt", "", $fname);
echo "\n".$cmd;
$output = shell_exec($cmd);
echo $output;
}else{
$message = "move_uploaded_file() Failed";
}
,这里是shell脚本
#!/bin/bash
echo $1 ' is the argument:' $2 ' is the second '
STRING="/var/www/html/devclassroomproject/powerpoints/"
echo $STRING$1/$2'.ppt '
unoconv $STRING$1/$2'.ppt'
pdftk $STRING$1/$2'.pdf' burst output $STRING$1/$1'_%2d.pdf'
这就是从回声印刷:
importppt.sh pptest pptestpptest is the argument: pptest is the second
/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt
编辑: 破译我的调试 命令: “importppt.sh pptest pptest” importppt.sh是shell脚本; pptest是第一和第二个参数
通过在外壳脚本中的第一回波印刷:“pptest是参数:pptest是第二”
通过在脚本中的第二回波验证的完整路径印刷这确实存在pdf文件:“/var/www/html/devclassroomproject/powerpoints/pptest/pptest.ppt”
遗憾的混乱
我不是一个php编码器,但它看起来像是如果你在'chmod'行之后添加一行'echo name = $ name,fname = $ fname'',你应该看到你的问题的来源,祝你好运! – shellter 2014-11-03 02:49:23
这些值传递到我的shell脚本,然后由shell脚本打印,就像我说的,我知道我使用的命令是正确的,因为shell脚本正在运行它打印的参数与我在使用命令行时完全相同。谢谢你。即时猜测PHP要么是不承认unoconv或pdftk,因为我已经下载它们,或没有权限使用它们或什么 – 2014-11-03 02:54:09
以及我的观点是你的调试文本看起来非常可疑,即'pptest pptestpptest是参数:pptest是第二' 。作为第一个和第二个参数你是否通过pptest?你为什么得到'pptestpptest'。可能你的'unoconv'是不可靠的,但我认为这个概率要低得多。你应该在std-err上得到mesg,比如'unknown cmd:unoconv',或者'uoconv:usage:.....'祝你好运。 – shellter 2014-11-03 03:06:05