Print directly to network printer using php

孤街浪徒 提交于 2019-11-27 20:56:11

If you used the command line PHP (CLI) the printing to network printers would work. Your $addr is correct by the way.

The issue lies with PHP when you combine it with Apache. In windows, your php scripts would run under the user SYSTEM. Because of security concerns, all network resources are not visible to SYSTEM.

To resolve this problem, create a new user with admin privileges (or at least with Network Resource visibility). In Windows, if you run Apache as a service, click on the SERVICE button in the Apache Service Monitor. Under Apache 2.2, right click on properties. Under the LOGIN tab, change the user from SYSTEM to your newly created user account. Restart Apache. You should be able to run your PHP script to print to network printers now.

Try using either "s with 4\ or 's with 3. eg:

$handle = printer_open("\\\\192.168.0.8\\Canon MF4320-4350");
// or
$handle = printer_open('\\\192.168.0.8\Canon MF4320-4350');

Also, try using a domain name rather than IP (eg. computer-name or full.address.example.com).

Just looking at that string, it feels very much as if it's likely to be caused by back-slash escaping going wrong.

Debugging tip: Set your network address in a variable rather than directly in printer_open(). Then use print() or similar to display the value.

<?php
   $addr = '\\\\192.168.0.8\\Canon MF4320-4350';
   print $addr;
   printer_open($addr);
   ...
?>

This will allow you to see the value of the string that you're using, which might help you see what's going wrong, and more importantly, help you see how to fix it.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!