note 89731 modified in function.printer-open by danbrown
| From: | danbrown@php.net | Date: | Fri, 20 Mar 2009 18:13:33 +0000 |
| Subject: | note 89731 modified in function.printer-open by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152219@lists.php.net to get a copy of this message | ||
I had been playing around with trying to get PHP to print to a network server off and on for quite
some time, and I finally came across somebody who had the piece of the puzzle I've been
missing.
Like I said, the printer I've been trying to print to is a network printer, so I had been
trying to open the printer as follows:
<?php printer_open("\\\\servername\\printername"); ?>
What I had been missing is that the function needed the internet host name of the server, which
includes the domain name. So, let's say my print server was called "PServer" and my
network's domain was called php.net:
<?php printer_open("\\\\Pserver.php.net\\printername"); ?>
This will more than likely work, then you can open and print a file as follows:
<?php
$printer = "\\\\Pserver.php.net\\printername");
if($ph = printer_open($printer))
{
// Get file contents
$fh = fopen("filename.ext", "rb");
$content = fread($fh, filesize("filename.ext"));
fclose($fh);
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content);
printer_close($ph);
}
else "Couldn't connect...";
?>
--was--
I had been playing around with trying to get PHP to print to a network server off and on for quite
some time, and I finally came across somebody who had the piece of the puzzle I've been
missing.
Like I said, the printer I've been trying to print to is a network printer, so I had been
trying to open the printer as follows:
printer_open("\\\\servername\\printername");
What I had been missing is that the function needed the internet host name of the server, which
includes the domain name. So, let's say my print server was called "PServer" and my
network's domain was called php.net:
printer_open("\\\\Pserver.php.net\\printername");
This will more than likely work, then you can open and print a file as follows:
$printer = "\\\\Pserver.php.net\\printername");
if($ph = printer_open($printer))
{
// Get file contents
$fh = fopen("filename.ext", "rb");
$content = fread($fh, filesize("filename.ext"));
fclose($fh);
// Set print mode to RAW and send PDF to printer
printer_set_option($ph, PRINTER_MODE, "RAW");
printer_write($ph, $content);
printer_close($ph);
}
else "Couldn't connect...";
http://php.net/manual/en/function.printer-open.php