PHP打印到本地热敏打印机,没有网络名称就不起作用


PHP printing to local Thermal Printer, does not work without networkname

我在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');
}

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

如果我断开 pc 与网络的连接,PHP 将无法再连接到 ''''localhost 或 ''''COMPUTER-NAME。

我已经尝试过这样的事情:fopen('TM-T88V'),fopen('''

''.''TM-T88V'),但我不断得到"[function.fopen]:无法打开流:没有这样的文件或目录..."。

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

你试过fopen("PRN", "w")吗?

这是我在

PHP 中用于打印作业的代码片段:

$handle = printer_open('Printer Name in windows here');
if($handle) { // Make sure the printer is present before sending the job
// print job here
}