PDA

View Full Version : Possibility, Printing - PHP


Markpyro
01-09-2007, 11:05 PM
Would it be possible to, on my network, to host a server running php, that a computer on the same network would upload a file to, which then PHP would send a command to my computer (a print command. I would also host the server) which would in turn send a command to the network printer to print the uploaded document?

The reason being, my mother works for Cisco, which allows her to work at home, but in order to connect to the VPN she has to be behind a Cisco router. Now, since Cisco routers aren't wireless, we needed two routers, one being wireless, so that I could have internet access as well. Unfortunately, due to restrictions, she cant connect to the printer via the network.

Now, for partially my sake in learning this portion of PHP, and partially to solve the problem of not being able to print, would this be possible? What would the code look like (how to issue a system command in PHP)?


Thanks :P. I'm curious as to whether this works.

-MP


http://pyrom.net/sigs/manual/hr.png
http://pyrom.net/sigs/manual/sigimage.png
*http://pyrom.net/test/blamecountimage.php*http://pyrom.net/test/lastblameimage.php*
http://pyrom.net/test/blameclick.png (http://pyrom.net/test/blame.php)

TimP
01-10-2007, 2:01 PM
On a Unix/Linux based system it would be as easy as system("lpr file"); but I assume you're on a Windows machine. A quick search on Google found this:

http://www.robvanderwoude.com/index.html

So it looks like you could do something like system("RUNDLL32 PRINTUI.DLL,PrintUIEntry /a uploadedfile");

Modred
01-10-2007, 5:31 PM
TimP, just sending the file to lpr would work, even if it's something like a Word document? Assuming you have nothing on your Linux system that can read the Word document format.

TimP
01-10-2007, 7:24 PM
Depends on which printing system you're using. BSD lpr will just pass the raw data to the printer so if you used it to send a Word doc, you'd get garbage printed out. I believe CUPS does some sort of MIME-type matching to handle natively unprintable formats (like Word docs) and converts them to something the printer can use. I'm not entirely familiar with CUPS so I'm not sure how it does this, but supposedly it works. CUPS has SysV and BSD printing front ends so you can use traditional print commands to pass data to CUPS. I've just started looking into setting up *nix print servers in the last day or two so my explanation may not be 100% correct.

The following excerpt is from the Wikipedia article on CUPS (emphasis added):

"The primary advantage of CUPS is that it is a standard and modularised printing system that can process numerous data formats on the print server. Before CUPS, it was difficult to find a standard printer management system that would accommodate the very wide variety of printers on the market using their own printer languages and formats. For instance, the System V and Berkeley printing systems were largely incompatible with each other, and they required complicated scripts and workarounds to convert the program's data format to a printable format. They often could not detect the file format that was being sent to the printer and thus could not automatically and correctly convert the data stream. Additionally, data conversion was performed on individual workstations rather than a central server."

I'm hoping to get CUPS setup sometime in the next few weeks so we'll see if it's as good as it sounds. :)