Skip to content

Commit

Permalink
add checks for failed tmp file creation, closes #362
Browse files Browse the repository at this point in the history
  • Loading branch information
mike42 committed Oct 5, 2019
1 parent 083f92d commit f60959f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function finalize()

// Build command to work on data
$tmpfname = tempnam(sys_get_temp_dir(), 'print-');
if ($tmpfname === false) {
throw new Exception("Failed to create temp file for printing.");
}
file_put_contents($tmpfname, $data);
$cmd = sprintf(
"lp -d %s %s",
Expand Down
3 changes: 3 additions & 0 deletions src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ protected function finalizeWin($data)
}
/* Final print-out */
$filename = tempnam(sys_get_temp_dir(), "escpos");
if ($filename === false) {
throw new Exception("Failed to create temp file for printing.");
}
file_put_contents($filename, $data);
if (!$this -> runCopy($filename, $device)) {
throw new Exception("Failed to copy file to printer");
Expand Down

0 comments on commit f60959f

Please sign in to comment.