脚本宝典收集整理的这篇文章主要介绍了如何在PHP中扫描,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么我的PHP脚本无法访问USB扫描仪,但$USER能够?
我在工作中开始提出这个问题,但现在我在家,所以我将尝试从PHP脚本访问Brother MFC-9840CDW USB扫描仪.
if($_POST['ScanDevice'] == "brother3:net1;dev0") // if MFC-7840W network scanner {$scanner = escaPEshellarg($_POST['ScanDevice']);} elseif($_POST['ScanDevice'] == "brother3:bus3;dev1") // if MFC-7840W USB scanner {$scanner = escapeshellarg($_POST['ScanDevice']);} elseif($_POST['ScanDevice'] == "brother3:net1;dev1") // if MFC-9840CDW network scanner {$scanner = escapeshellarg($_POST['ScanDevice']);} elseif($_POST['ScanDevice'] == "brother3:bus6;dev1") // if MFC-9840CDW USB scanner {$scanner = escapeshellarg($_POST['ScanDevice']);} $command = "scanimage -d {$scanner} --resolution {$_POST[ScanResolution]} --mode {$_POST[ScanColor]} > {$filename}"; echo exec($command,$op,$result); if($result > 0) {die("ERROR");}
PHP脚本适用于网络扫描程序,但不适用于USB扫描程序.
如果我选择任一USB扫描仪(当前为MFC-9840CDW)并运行脚本,则文件/VAR/LOG/apache2/error.log显示:
scanimage: open of device brother3:bus6;dev1 Failed: Invalid @R_777_643@
问题出现了:设备brother3:bus6; dev1是否存在?
以下是scanimage –list-devices在家中终端输入时显示的内容(MFC-9840CDW所在的位置):
[piXMa] udp_command: No data received (select): timed out [pixma] udp_command: No data received (select): timed out [pixma] udp_command: No data received (select): timed out [pixma] Cannot read scanner make & model: �+�& device `brother3:net1;dev1' is a Brother MFC-7840W SCANNER device `brother3:net1;dev0' is a Brother MFC-9840CDW Scanner-MFC-9840CDW device `brother3:bus6;dev1' is a Brother MFC-9840CDW USB scanner
为了证明USB扫描器适用于$USER,我在终端中输入以下命令:
scanimage --test -d 'brother3:bus6;dev1'
这表现了:
scanimage: rounded value of br-x From 215.9 to 215.88 scanimage: rounded value of br-y from 355.6 to 355.567 scanimage: scanning image of size 1664x2776 pixels at 24 bITs/pixel scanimage: acquiring RGB frame,8 bits/sample scanimage: reading one scanline,4992 bytes... PASS scanimage: reading one byte... PASS scanimage: stepped read,2 bytes... PASS scanimage: stepped read,4 bytes... PASS
为了证明用户www-data无法访问USB扫描器,我在终端中输入以下命令:
sudo -u www-data scanimage --test -d 'brother3:bus6;dev1'
这表现了:
scanimage: open of device brother3:bus6;dev1 Failed: Invalid argument
要查找USB扫描仪所属的组,必须知道USB扫描仪的名称.要查找USB扫描仪的名称,请输入命令:
lsusb -v
显示(以及其他行):
Bus 002 Device 007: ID 04f9:01cc Brother Industries,Ltd
然后,通过输入命令找到USB扫描仪所属的组:
ls -al /dev/bus/usb/002/007
这表现了:
crw-rw-r--+ 1 root lp 189,134 Dec 12 22:30 /dev/bus/usb/002/007
USB扫描仪所属的组是lp. $USER能够访问USB扫描仪的原因是因为$USER是lp组的成员,而www-data不是.输入命令即可证明:
grep ^lp /etc/group
这表现了:
lp:x:7:root,arya
sudo usermod -a -G lp www-data
然后,通过输入grep ^ lp / etc / group再次测试结果,现在显示:
lp:x:7:root,arya,www-data
然后,重新启动apache以确保上面的操作已注册:
sudo apache2ctl -k restart
然后,测试以查看www-data是否可以从终端访问USB扫描仪:
sudo -u www-data scanimage --test -d 'brother3:bus6;dev1'
这表现了:
scanimage: rounded value of br-x from 215.9 to 215.88 scanimage: rounded value of br-y from 355.6 to 355.567 scanimage: scanning image of size 1664x2776 pixels at 24 bits/pixel scanimage: acquiring RGB frame,8 bits/sample scanimage: reading one scanline,4992 bytes... PASS scanimage: reading one byte... PASS scanimage: stepped read,2 bytes... PASS scanimage: stepped read,4 bytes... PASS
然后,再次运行原始PHP脚本以查看它是否可以访问USB扫描仪并扫描文档…
成功!
以上是脚本宝典为你收集整理的如何在PHP中扫描全部内容,希望文章能够帮你解决如何在PHP中扫描所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。