PHP打印到本地热敏打印机,没有网络名称就无法工作

Bau*_*sma 5 php printing fopen thermal-printer

我在PHP中构建了一个可以直接打印到热敏打印机的POS(销售点)应用程序.在大多数情况下,我使用WAMP在本地Web服务器上运行应用程序.

部分打印代码是:

$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');
}
Run Code Online (Sandbox Code Playgroud)

只要PC连接到网络,此代码就可以正常工作.我可以使用fopen和"LOCALHOST"或"COMPUTER-NAME"将PHP连接到共享打印机(在同一台PC上或在网络中的PC上):fopen("\\ localhost\TM-T88V") , 'W');

如果我断开电脑与网络的连接,PHP将无法再连接到\\ localhost或\\ COMPUTER-NAME.

我尝试过这样的事情:fopen('TM-T88V'),fopen('\\.\ TM-T88V'),但我一直得到"[function.fopen]:无法打开流:没有这样的文件或目录...".

如何在没有活动网络连接的情况下连接到本地(共享)打印机(最好是通过名称)?

alg*_*net 3

你有没有尝试过fopen("PRN", "w")