diff --git a/index.php b/index.php index f13c092..db22760 100644 --- a/index.php +++ b/index.php @@ -102,88 +102,75 @@ - - - - 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(); -// append to filename if set, otherwise date only -if (isset($_POST['filenaming'])) { - if (empty($_POST['filenaming'])) { - $filename = date($date_format); - } else { - $filename = date($date_format)."_".$_POST['filenaming']; - } - } else { - $filename = date($date_format); - } - -// do it! - $process = proc_open($scanprog . " -d " . $_POST['device'] . " --output-file " . $scans_dir . $filename . "-%04d --source " . $_POST['source'] . " --mode " . $_POST['mode'] . " --resolution " . $sResolution . " -l " . $_POST['l'] . " -t " . $_POST['t'] . " -x " . $sX . " -y " . $_POST['y'], $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)) { - if ($firstFile=="") $firstFile = $file; - array_push($inputFiles, $file); + 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(); + // append to filename if set, otherwise date only + if (isset($_POST['filenaming'])) { + if (empty($_POST['filenaming'])) { + $filename = date($date_format); + } else { + $filename = date($date_format)."_".$_POST['filenaming']; + } + } else { + $filename = date($date_format); + } + // do it! + $process = proc_open($scanprog . " -d " . $_POST['device'] . " --output-file " . $scans_dir . $filename . "-%04d --source " . $_POST['source'] . " --mode " . $_POST['mode'] . " --resolution " . $sResolution . " -l " . $_POST['l'] . " -t " . $_POST['t'] . " -x " . $sX . " -y " . $_POST['y'], $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)) { + if ($firstFile=="") $firstFile = $file; + array_push($inputFiles, $file); + } + } + if (count($inputFiles)) { + $path=""; + foreach ($inputFiles as $file) { + $path .= "pnm:" . $scans_dir . $file; + } + //exec($convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg"); + // make a (multi-page) pdf file from the scanned pnm files + // we have to set density to match the scan resolution and then calculate the width to pixels in order to make the pdf correct + exec($convert . ' -density ' . $sResolution . ' -page ' . $sX . ' ' . $path . ' ' . $scans_dir . $filename . '.pdf'); + // $output = $convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg"; + // $output .= ($convert . " " . $path . " " . $scans_dir . $filename . ".pdf"); + echo "Scan Successful!"; + } else { + echo "Scan Failed!"; + } + ob_flush(); + echo ""; } - if (count($inputFiles)) { - $path=""; - foreach ($inputFiles as $file) { - $path .= "pnm:" . $scans_dir . $file; - } -//exec($convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg"); -// make a (multi-page) pdf file from the scanned pnm files -// we have to set density to match the scan resolution and then calculate the width to pixels in order to make the pdf correct -exec($convert . ' -density ' . $sResolution . ' -page ' . $sX . ' ' . $path . ' ' . $scans_dir . $filename . '.pdf'); - -// $output = $convert . " pnm:" . $scans_dir . $firstFile . " -strip " . $scans_dir . $firstFile . ".jpg"; - // $output .= ($convert . " " . $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(); - echo ""; - - - } -?> - - + ?>

Previous Document Scans (PDF)