PHP printing to a local thermal printer does not work without a network name

I created a POS (Point of Sale) application in PHP that can print directly to a thermal printer. In most cases, I run the application on the local web server using WAMP.

Part of the print code:

$printer = "\\\\localhost\\TM-T88V";

// Open connection to the thermal printer
$fp = fopen($printer, "w");
if (!$fp){
  die('no connection');
}

$data = " PRINT THIS ";

// Cut Paper
$data .= "\x00\x1Bi\x00";

if (!fwrite($fp,$data)){
  die('writing failed');
}

This code works fine while the PC is connected to the network. I can get PHP to connect to a shared printer (either on the same PC or on a PC on the network) using fopen and "LOCALHOST" or "COMPUTER-NAME": fopen ("\\ localhost \ TM-T88V"), 'W ');

If I disconnect the computer from the network, PHP will no longer be able to connect to \\ localhost or \\ COMPUTER-NAME.

, : fopen ('TM-T88V'), fopen ('\\.\TM-T88V'), "[function.fopen]: : ...".

( ) ( ) ?

+5
2

fopen("PRN", "w")?

+3

, PHP:

$handle = printer_open('Printer Name in windows here');

if($handle) { // Make sure the printer is present before sending the job
// print job here
}
0

All Articles