Modified php
This commit is contained in:
parent
f5fb5ed69c
commit
2e6f5ce7fa
112
index.php
112
index.php
@ -9,79 +9,71 @@
|
|||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
// Configuration
|
// Configuration
|
||||||
|
|
||||||
|
// Directories
|
||||||
$app_dir = "/var/www/scan/"; // Absolute path to where this app directory is - must end with a /
|
$app_dir = "/var/www/scan/"; // Absolute path to where this app directory is - must end with a /
|
||||||
$scan_dir = "scans/"; // Relative path inside application directory that holds the scans - must end with a /
|
$scan_dir = "scans/"; // Relative path inside application directory that holds the scans - must end with a /
|
||||||
|
|
||||||
|
// Formats
|
||||||
|
$date_format = "Y-m-d_H.i.s"; // Date format to use for file naming - in PHP date code format
|
||||||
|
|
||||||
|
// Binarys
|
||||||
|
$scanimage = "/usr/bin/scanimage"; // Absolute path to scanimage binary
|
||||||
|
$convert = "/usr/bin/convert"; //Absolute path to scanimage binary
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Don't touch below!
|
// Don't touch below!
|
||||||
|
|
||||||
|
// initialize scanned files directory path
|
||||||
$scans_dir = $app_dir . $scan_dir;
|
$scans_dir = $app_dir . $scan_dir;
|
||||||
|
|
||||||
|
// append to filename if set, otherwise date only
|
||||||
if (isset($_POST["filenaming"])) {
|
if (isset($_POST["filenaming"])) {
|
||||||
$filename = date("Y-m-d_H.i.s")."_".$filenaming;
|
$filename = date("Y-m-d_H.i.s")."_".$filenaming;
|
||||||
} else {
|
} else {
|
||||||
$filename = date("Y-m-d_H.i.s");
|
$filename = date("Y-m-d_H.i.s");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// are we being called as a result of a scan or just initial page view?
|
||||||
if (isset($_POST["scan"])) {
|
if (isset($_POST["scan"])) {
|
||||||
$findScanner = array(
|
$descriptorspec = array(
|
||||||
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
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
|
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
||||||
2 => array("pipe", "w") // stderr is a file to write to
|
2 => array("pipe", "w") // stderr is a file to write to
|
||||||
);
|
);
|
||||||
$env=array();
|
$cwd = '/tmp';
|
||||||
$process = proc_open("/usr/bin/sane-find-scanner", $findScanner, $pipes, '/tmp', $env);
|
$env = array();
|
||||||
if (is_resource($process)) {
|
$process = proc_open("$scanimage -d $_POST[device] --output-file $scans_dir$fileName-%04d --source $_POST[source] --mode ".
|
||||||
$data = stream_get_contents($pipes[2]);
|
"$_POST[mode] --resolution $_POST[resolution] -l $_POST[l] -t $_POST[t] -x $_POST[x] -y $_POST[y]", $descriptorspec, $pipes, $cwd, $env);
|
||||||
$data .= stream_get_contents($pipes[1]);
|
if (is_resource($process)) {
|
||||||
}
|
$errors = stream_get_contents($pipes[2]);
|
||||||
proc_close($process);
|
$output = stream_get_contents($pipes[1]);
|
||||||
$match = preg_match('/libusb:\d+:\d+/', $data, $matches);
|
|
||||||
if ($match&&count($matches)) {
|
|
||||||
$address=$matches[0];
|
|
||||||
}
|
|
||||||
$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 file to write to
|
|
||||||
);
|
|
||||||
$cwd = '/tmp';
|
|
||||||
$env = array();
|
|
||||||
|
|
||||||
$process = proc_open("/usr/bin/scanimage -d $device --output-file ".
|
|
||||||
"$scans_dir . $fileName-%04d --quick-format Letter".
|
|
||||||
" --mode $_POST[mode] --resolution $_POST[quality] --source Automatic Document Feeder", $descriptorspec, $pipes, $cwd, $env);
|
|
||||||
|
|
||||||
if (is_resource($process)) {
|
|
||||||
$errors = stream_get_contents($pipes[2]);
|
|
||||||
$output = stream_get_contents($pipes[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$dirList = scandir($scans_dir);
|
|
||||||
$inputFiles = array();
|
|
||||||
$firstFile = "";
|
|
||||||
foreach ($dirList as $file) {
|
|
||||||
if (stristr($file, $fileName)) {
|
|
||||||
//this is one of our input files
|
|
||||||
if ($firstFile=="") $firstFile = $file;
|
|
||||||
array_push($inputFiles, $file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($inputFiles))
|
|
||||||
{
|
|
||||||
$path="";
|
|
||||||
foreach ($inputFiles as $file) {
|
|
||||||
$path .= "pnm:" . $scans_dir . $file;
|
|
||||||
}
|
|
||||||
$output = `/usr/bin/convert pnm:$scans_dir$firstFile -resize '>300x' -strip $scans_dir$firstFile.jpg`;
|
|
||||||
$output .= `/usr/bin/convert -page a4 $path $scans_dir$fileName.pdf`;
|
|
||||||
echo "Scan Successful!";
|
|
||||||
} else {
|
|
||||||
echo "Scan Failed! No pages were scanned. Is there a document in the scanner?";
|
|
||||||
}
|
}
|
||||||
|
$dirList = scandir($scans_dir);
|
||||||
|
$inputFiles = array();
|
||||||
|
$firstFile = "";
|
||||||
|
foreach ($dirList as $file) {
|
||||||
|
if (stristr($file, $fileName)) {
|
||||||
|
if ($firstFile=="") $firstFile = $file;
|
||||||
|
array_push($inputFiles, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($inputFiles)) {
|
||||||
|
$path="";
|
||||||
|
foreach ($inputFiles as $file) {
|
||||||
|
$path .= "pnm:" . $scans_dir . $file;
|
||||||
|
}
|
||||||
|
$output = `/usr/bin/convert pnm:$scans_dir$firstFile -resize '>300x' -strip $scans_dir$firstFile.jpg`;
|
||||||
|
$output .= `/usr/bin/convert -page a4 $path $scans_dir$fileName.pdf`;
|
||||||
|
echo "Scan Successful!";
|
||||||
|
} else {
|
||||||
|
echo "Scan Failed! No pages were scanned. Is there a document in the scanner?";
|
||||||
|
}
|
||||||
ob_flush();
|
ob_flush();
|
||||||
echo "";
|
echo "";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="pure-g">
|
<div class="pure-g">
|
||||||
@ -128,10 +120,9 @@ if (isset($_POST["scan"])) {
|
|||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="scan" value="yes" />
|
<input type="hidden" name="scan" value="yes" />
|
||||||
<input type="submit" onclick="this.disabled=true;this.value='Scanning - PLEASE be patient!';this.form.submit();" value="Scan!" class="pure-button pure-button-primary" />
|
<input type="submit" onclick="this.disabled=true;this.value='Scanning - PLEASE be patient!';this.form.submit();" value="Scan!" class="pure-button pure-button-primary" />
|
||||||
</fieldset>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pure-u-1 pure-u-md-1-3">
|
<div class="pure-u-1 pure-u-md-1-3">
|
||||||
<fieldset>
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<legend><h3>File Options</h3></legend>
|
<legend><h3>File Options</h3></legend>
|
||||||
<label for="filetype">File Type</label>
|
<label for="filetype">File Type</label>
|
||||||
@ -144,10 +135,9 @@ if (isset($_POST["scan"])) {
|
|||||||
<label for="filenaming">File Naming</label>
|
<label for="filenaming">File Naming</label>
|
||||||
<input id="filenaming" class="pure-input-rounded" placeholder="Append to filename">
|
<input id="filenaming" class="pure-input-rounded" placeholder="Append to filename">
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1 pure-u-md-1-3">
|
<div class="pure-u-1 pure-u-md-1-3">
|
||||||
<fieldset>
|
|
||||||
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
<legend><h3>Page Size</h3></legend>
|
<legend><h3>Page Size</h3></legend>
|
||||||
|
Loading…
Reference in New Issue
Block a user