2014-02-07 315 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

相關問題