PHP打印到本地热敏打印机,如果没有网络名称,则无法使用 [英] PHP printing to local Thermal Printer, does not work without networkname

查看:151
本文介绍了PHP打印到本地热敏打印机,如果没有网络名称,则无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've build a POS (Point of Sale) application in PHP that can print directly to a thermal printer. In most cases i run the application on a local webserver using WAMP.

部分打印代码为:

$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连接到网络,此代码就可以正常工作. 我可以使用fopen和"LOCALHOST"或"COMPUTER-NAME"使PHP连接到共享打印机(在同一台PC上,或在网络中的PC上):fopen("\\ localhost \ TM-T88V" ,'w');

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

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

If I disconnect the pc from the network, PHP can no longer connect to \\localhost or \\COMPUTER-NAME.

我已经尝试过类似的操作:fopen('TM-T88V'),fopen('\\.\ TM-T88V'),但我不断收到"[function.fopen]:无法打开流:没有这样的信息文件或目录...".

I've tried things like: fopen('TM-T88V'), fopen('\\.\TM-T88V'), but I keep getting "[function.fopen]: failed to open stream: No such file or directory...".

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

How do I connect to a local (shared) printer (preferably by name) without having an active network connection?

推荐答案

您是否尝试过fopen("PRN", "w")?

这篇关于PHP打印到本地热敏打印机,如果没有网络名称,则无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆