-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan.php
47 lines (38 loc) · 1.36 KB
/
scan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$servername = "localhost";
$username = "scan";
$password = "";
$db = "print";
ob_implicit_flush(true);
ob_end_flush();
$filename = uniqid() . ".jpg";
//$cmd = "sudo scanimage -p --format png --resolution 300 -x 215 -y 280 > " . $filename;
$cmd = "sudo scanimage -p --format tiff --resolution 300 -x 215 -y 280 | convert tiff:- " . $filename;
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("pipe", "w") // stderr is a pipe that the child will write to
);
flush();
$process = proc_open($cmd, $descriptorspec, $pipes, realpath('./tmp'), array());
if (is_resource($process)) {
while (false !== ($char = fgetc($pipes[2]))) {
//print $char;
if(ord($char) == 13) {
echo "\r";
} else {
echo $char;
}
flush();
}
echo "\r" . $filename;
//Now add filename to MySQL
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO scan_jobs (image_name) VALUES ('" . $filename . "');";
$result = $conn->query($sql);
}
?>