|
printer_list
Return an array of printers attached to the server
()
Example 2001. printer_list() example<?php Code Examples / Notes » printer_listgabriel dot smagghe
You can use all the array data, with no crash. For that you can do this : $getprt=printer_list(PRINTER_ENUM_LOCAL| PRINTER_ENUM_SHARED ); if ($debugprt){echo "<pre> get prt"; print_r($getprt); echo "</pre>"; echo count($getprt); } $printers = serialize($getprt); //echo $printers ; $pp=str_replace _ (";s:11:\"DESCRIPTION\";",";s:4:\"DESC\";",_ str_replace(";s:7:\"COMMENT\";",";s:4:\"COMM\";",$printers)); $printers=unserialize($pp); if ($debugprt){echo "<pre> pp :"; print_r($printers); echo "</pre>"; echo count($printers); } An that's ok saidyjade
You can still get the "NAME" of printers through the printer_list as only the array keys "DESCRIPTION" and "COMMENT" crash and not the "NAME" key. $list_printers = printer_list(PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED); // get the name of the first returned printer //(you can add array walk function to get all printer names if you wish.. but I am lazy) $this_printer = $list_printers[0]["NAME"]; // open a connection to your printer $my_printer = printer_open($this_printer); .. blah blah The output of var_dump (as an example) var_dump( printer_list(PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED) ); array(1) { [0]=> array(3) { ["NAME"]=> string(14) "Canon BJC-4550" ["DESCRIPTION"]=> string(30) "Canon BJC-4550,Canon BJC-4550," ["COMMENT"]=> string(0) "This is my funky printer!" } } As you can see var_dump (under variable functions in the manual) shows and/or retrieves the corrent information but if you try to place into a variable or read the variable it crashes either apache using php4apache.dll or php when you the command line client or cgi. So as long as you do not get the comment or description it will list your printers. ewilde aht bsmdevelopment dawt com
printer_list was not working for me and the docs are a little sparse. So, I took a look at the code for php_printer.dll (which is at http://viewcvs.php.net/viewvc.cgi/pecl/printer/printer.c, BTW) to figure out what was going on. Basically, this function is a wrapper for the Windows function EnumPrinters. You can find this function documented in MSDN (which is at http://msdn.microsoft.com). Do a search for EnumPrinters and you should see the function itself as the first hit in the search list. There is a lot more information about what the parameters to the function mean and the results returned. The printer_list function basically copies the enumtype, name and level parameters directly to the Flags, Name and Level parameters of EnumPrinters, calls the function and then copies all of the fields, in the appropriate data structure returned for the level of information requested, back to the results array. jt
As saidyjade mentioned below, printer_list crashes Apache when you pound the resulting array too much. I don't know why this happens, somebody should look deeper into the subject... I have found out, contrary to saidyjade, that also just getting the NAME attribute (and remember, it's case-sensitive! :-) can crash Apache. Here's what I had: <?php foreach (printer_list(PRINTER_ENUM_CONNECTIONS) as $printer) echo "<option value=\"" . addslashes(strtoupper($printer["NAME"])) . "\">" . strtoupper($printer["NAME"]) . "\n"; ?> This snippet worked alright, whereas <?php foreach (printer_list(PRINTER_ENUM_CONNECTIONS) as $printer) echo "<option value=\"" . addslashes(strtoupper($printer["NAME"])) . "\"" . ((strtoupper($printer["NAME"])) ? " selected" : "") . ">" . strtoupper($printer["NAME"]) . "\n"; ?> crashed Apache everytime the page was loaded. I played around a bit and found this snippet not crashing: <?php foreach (printer_list(PRINTER_ENUM_CONNECTIONS) as $printer) { $curprin = strtoupper($printer["NAME"]); echo "<option value=\"" . addslashes($curprin) . "\"" . (($curprin == $user["drucker"]) ? " selected" : "") . ">$curprin\n"; } ?> So, in essence you just need to be careful about how much you use the array and if necessary define help variables that you can use as much as you want. Hope this saves somebody some more minutes... |
Change Languageprinter_abort printer_close printer_create_brush printer_create_dc printer_create_font printer_create_pen printer_delete_brush printer_delete_dc printer_delete_font printer_delete_pen printer_draw_bmp printer_draw_chord printer_draw_elipse printer_draw_line printer_draw_pie printer_draw_rectangle printer_draw_roundrect printer_draw_text printer_end_doc printer_end_page printer_get_option printer_list printer_logical_fontheight printer_open printer_select_brush printer_select_font printer_select_pen printer_set_option printer_start_doc printer_start_page printer_write |