php shell_exec with params

时间:2018-05-15 10:21:02

标签: php

我想使用php运行此命令:

kdu_expand -i 1.jp2 -o 1.tif -region '{0,0},{0.5,0.5}'

home/kakadu文件夹中的kdu_expand.exe。

<?php

require "api/include/database.php";

if ($_GET) {
    if ($_GET['link'] && $_GET['id'] && $_GET['height'] && $_GET['width']) {
        $link = $_GET['link'];
        $id = $_GET['id'];
        $height = $_GET['height'];
        $width = $_GET['width'];

        $db = Database::connect();

        $sql = "SELECT * FROM stacks WHERE stack_id = ?";
        $query = $db->prepare($sql);
        $query->execute(array($id));
        if ($query->rowCount() > 0) {
            $stacks = $query->fetchAll(PDO::FETCH_ASSOC);
            mkdir("/SharedFolder/tmp/" . $id, 0777);
            foreach($stacks as $stack) {
                $region = [
                    'left'      => $stack['rect_x'] / $width,
                    'top'       => $stack['rect_y'] / $height,
                    'width'     => $stack['rect_w'] / $width,
                    'height'    => $stack['rect_h'] / $height
                ];

                $argument = "-i /SharedFolder/stacks/{$plink} -o /SharedFolder/tmp/{$id}/{$stack['id']}.tif -region '{{$region['top']},{$region['left']}},{{$region['height']},{$region['width']}}'";
                echo $argument . '<br />';
                shell_exec("/home/kakadu/kdu_expand.exe {$argument}");
            }
        }
    }
}

它没有发生任何事情..如果我在腻子上面运行命令,它运作良好。但是在php中它不会发生任何事情。

1 个答案:

答案 0 :(得分:0)

当我在shell中尝试此命令时;它返回:

  

kdu_expand.exe:无法执行二进制文件:执行格式错误

我改变了我的命令然后工作:

shell_exec("cd /home/kakadu && kdu_expand {$argument}");