使用来自linux主机的php扫描scanimage

时间:2013-04-26 23:21:32

标签: php linux image scanning

以下是这种情况:我正在尝试使用PHP在Linux主机上调用scanimage,然后将生成的文件保存到Web目录中以备将来使用。

以下代码不会产生任何错误,但是当我检出/ tmp目录时,file.pnm是空白的,扫描程序永远不会启动。

<?php
require('/var/www/olin/includes/functions.php');
$con = connect_db();

//setup the POST variables
if (isset($_POST['submit'])) {
    $fname = mysqli_real_escape_string($con, $_POST['fname']);
    $lname = mysqli_real_escape_string($con, $_POST['lname']);
    $license_no = mysqli_real_escape_string($con, $_POST['license_no']);
    $comments = mysqli_real_escape_string($con, $_POST['comments']);
} 


if ($license_no == '') { 
        $license_no = "None on File";
}

if ($fname == '' || $lname == '') { 
        echo '<h1 class="message">Can\'t submit visitor: you are missing information!</h1>'; 
} else {

    //setup the query and prepare it for exection
    $query=     "insert into visitors (fname, lname, license_no, redsheet, comments)" .
        " values (?, ?, ?, 'Allow', ?) on duplicate key update fname = values(fname)," .
        "lname = values(lname), license_no = values(license_no), redsheet = values(redsheet)," .
            "comments = values(comments)";
    $stmnt=     mysqli_prepare($con, $query);

    //bind the statement parameters to variables
    mysqli_stmt_bind_param($stmnt, "ssss", $fname, $lname, $license_no, $comments );

    //execute, then close the statment
    if (!mysqli_stmt_execute($stmnt)) {
        echo "Failed to ececute the query: " . mysqli_error($con);
        header('Refresh: 10; url=http://localhost/olin/visitor.php');
    } 
}

// we'll `try` to scan the license  if the checkbox is selected
if (isset($_POST['pic_id'])) { 
    // get the info from the db
    $query = 'select id from visitors where license_no = "'.$license_no.'"';

    $result = mysqli_query($con, $query);
    while ($row = mysqli_fetch_array($result)) {
        $id = $row['id'];

        // set up the path to save the id to (and put path into db for further look    up
        // and display)
        $dir = ( $id % 30 );

        $path = '/var/www/olin/images/licenses/'.$dir.'/'.$id.'-license.png';
        $path = addslashes(mysqli_real_escape_string($con, $path));
        $path1 = '/images/licenses/'.$dir.'/'.$id.'-license.png';

        // start the scan, and save image
        $command = '/home/jmd9qs/bin/scan.sh "'.$path.'"';

        $update = 'update visitors set id_pic = "'.$path1.'" where id="'.$id.'"';
        mysqli_query($con, $update) or die ('Error: ' . mysqli_error($con));
        exec($command);
        header('Location: http://localhost/olin/visitor.php');
    }
}

?>

任何人都可以提供任何提示吗?

更新:

我现在有服务器运行该命令(我知道由于Apache2错误日志而失败)。

这是我得到的错误:     scanimage: open of device brother3:bus2;dev1 failed: Invalid argument

我尝试将www-data用户添加到scannerlp组,但似乎没有效果......我正在使用的scanimage命令工作在我的普通用户和root用户之下,所以我现在肯定我正在使用的命令应该工作。我还是不知所措......

更新(再次):

我修复了代码中的一些错误...现在服务器扫描并成功保存图像!但是,它只运行一次然后由于一些奇怪的原因我必须运行scan.sh(我将scanimage命令放入)通过我的shell再次运行...否则我得到了同样的错误信息!

非常奇怪,我不知道为什么,建议需要!

0 个答案:

没有答案