2014-02-07 146 views
0

我有以下代码可以使其能够将某些内容打印到热敏收据打印机。使用PHP打印到热敏收据打印机使用PHP

if ($_GET['action'] == 'print') 
{ 
    $printer = "\\\\localhost\\zebra"; 

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

} 

虽然,当我运行它时,没有任何事情发生,没有错误。如何从PHP打印?

+1

怎么样使用printer_open功能.... http://www.php.net/manual/en/function.printer-open.php – user1844933

+0

它给我这:'调用未定义的函数printer_open()' – user3271851

+0

嗯,只是一个猜测,你是否在你的实际代码中使用“fclose”? – Passerby

回答

0

试试这个...

<?php 
if ($_GET['action'] == 'print') 
{ 
$printer = "\\\\localhost\\zebra"; 
if($ph = printer_open($printer)) 
{ 
    $data = " PRINT THIS "; 
    // Cut Paper 
    $data .= "\x00\x1Bi\x00"; 
    printer_write($ph, $data); 
    printer_close($ph); 
} 
else die('writing failed'); 
} 
?> 
+0

我得到这个错误:'调用未定义的函数printer_open()' – user3271851

+0

你在php.ini中启用了扩展吗? – user1844933

+0

我会在php.ini文件中放什么? – user3271851

相关问题