Page 1 of 1
Problem with Printer function, BUG??
Posted: Thu Jun 27, 2002 5:11 am
by a-jack
Hello,
i have some problem with the "printer" function.
I have installed an WAMP system with, PHP 4.2.1
i have added the "php_printer.dll".
when i want to connect to a printer i receive the message,
Warning: couldn't connect to the printer [h#Ž/htm] in c:\apache\htdocs\printer_1.php on line 4
-------
if ($submit) {
$handle = printer_open();
printer_write($handle, $text);
printer_close($handle);
}
------------------
When i try to list the attached printers with
----------------------
if ($auflisten) {
PRINTER_ENUM_SHARED);
$var_dump = printer_list(PRINTER_ENUM_LOCAL);
while(list($key, $value) = each($var_dump))
{
echo "$key, $value";
}
}
-----------------
i only receive
0, Array1, Array2, Array3, Array4, Array5, Array6, Array
what is the problem ?
thanks a lot
Jack
Posted: Thu Jun 27, 2002 5:22 am
by twigletmac
As a debugging tool print_r() works well, try
Code: Select all
echo '<pre>';
print_r($var_dump);
echo '</pre>';
Oh, and I'm assuming it's a typo but shouldn't
Code: Select all
PRINTER_ENUM_SHARED);
$var_dump = printer_list(PRINTER_ENUM_LOCAL);
be
Code: Select all
$var_dump = printer_list(PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED);
Mac
Debug
Posted: Thu Jun 27, 2002 7:02 am
by a-jack
Hello Mac,
thanks a lot for your help,
whe i try it now with your debugging, like
echo '<pre>';
print_r($var_dump);
echo '</pre>';
-----------------------
I receive an outut like,
Array
(
[0] => Array
(
[NAME] => HP Mopier 320 PS
[DESCRIPTION] => HP Mopier 320 PS,HP Mopier 320 PS,
[COMMENT] => Diesen Kommentar hat Kurt remote von einem Linux-Rechner aus auf dem win2K eingetragen. Methode: rpcclient...
)
[1] => Array
(
[NAME] => HP Mopier 320 PCL
[DESCRIPTION] => HP Mopier 320 PCL,HP Mopier 320 PCL,
[COMMENT] =>
)
[2] => Array
(
[NAME] => FRITZfax Drucker
[DESCRIPTION] => FRITZfax Drucker,FRITZ!fax,
[COMMENT] =>
)
[3] => Array
(
[NAME] => FRITZfax Color Drucker
[DESCRIPTION] => FRITZfax Color Drucker,FRITZ!Fax Color,
[COMMENT] =>
)
[4] => Array
(
[NAME] => Acrobat PDFWriter
[DESCRIPTION] => Acrobat PDFWriter,Acrobat PDFWriter,
[COMMENT] =>
)
[5] => Array
(
[NAME] => Acrobat Distiller
[DESCRIPTION] => Acrobat Distiller,AdobePS Acrobat Distiller,
[COMMENT] =>
)
)
################
so, but i do not know what is wrong
is my "while loop" wrong ?
thanks
Jack
Posted: Thu Jun 27, 2002 7:10 am
by twigletmac
Your while loop isn't working because it isn't taking into account the fact that the information is held in an array, try something like:
Code: Select all
foreach($var_name as $p_num => $info) {
echo 'Printer Number '.$p_num.' has the following information:<br />';
foreach($info as $title => $value) {
echo $title.' = '.$value;
echo '<br />';
}
}
Mac
Now it works, but..
Posted: Thu Jun 27, 2002 7:59 am
by a-jack
Hello MAC,
thanks a lot for your help,
sorry for my silly error, I am new in PHP,
the printer_open command
$handle = printer_open();
printer_write($handle, $text);
printer_close($handle);
does not work in PHP 4.2.1 ,
do you know why ?
also when i open PHPInfo in section "printers" there is no default printer found,
I tried it with PHP 4.06 there was one found and also the printer_open
command works
thanks a lot
Jack
Posted: Thu Jun 27, 2002 8:15 am
by twigletmac
Have you uncommented the
line in your php.ini and added the name of your default printer? As, for example:
Code: Select all
printer.default_printer = "HP Mopier 320 PS"
Another thing to try would be something along the lines of
Code: Select all
$handle = printer_open("HP Mopier 320 PS");
Obviously substituting the name in both cases with the printer that you wanted to use.
Mac
Works with ...
Posted: Thu Jun 27, 2002 8:36 am
by a-jack
Hi MAC,
it does not work when i insert the default printer name in the "PHP.INI"
printer.default_printer = "HP Mopier 320 PS"
also the output with "php_info" in the section Printers is corrupt
it shows not the Printer name, it shows like
#HTM#-d
When i insert the code so,
$handle = printer_open("HP Mopier 320 PS");
it work fine and i get an print output.
with the old php 4.0.6 version i had not such problem, it works also without
to insert a default printer name in PHP.INI
so it think it is a little bug ?
what do you mean ?
Where can i report this tho PHP ?
thanks
Jack
How use the printer name from array
Posted: Thu Jun 27, 2002 9:05 am
by a-jack
Hi Mac,
sorry when i ask again,
I am not so good with arrays, so if i use your code
-----------------------------------------
foreach($var_dump as $p_num => $info) {
echo 'Printer Number '.$p_num.' has the following information:<br />';
foreach($info as $title => $value) {
echo $title.' = '.$value;
echo '<br />';
}
}
}
-----------
i have this output,
Printer Number 0 has the following information:
NAME = HP Mopier 320 PS
DESCRIPTION = HP Mopier 320 PS,HP Mopier 320 PS,
COMMENT = Diesen Kommentar hat Kurt remote von einem Linux-Rechner aus auf dem win2K eingetragen. Methode: rpcclient...
-------------
I need now the Printer Name, which is behind "NAME"
i do not know how i can evaluate the array,
can you help me ?
thanks a lot
Jack
Posted: Thu Jun 27, 2002 9:10 am
by twigletmac
To get the name of the first printer in the array:
Code: Select all
$var_dump = $var_dump = printer_list(PRINTER_ENUM_LOCAL | PRINTER_ENUM_SHARED);
$printer_name = $var_dumpї0]ї'NAME'];
should do it.
Mac