I want to scan from my PHP script. I'm using Ubuntu 14.04 LTS, a Brother MFC-7840W scanner (located at work), and a Brother MFC-9840CDW (located at home). I can scan from the terminal and PHP when either scanner is connected to the computer as a network scanner. However, I cannot scan from PHP when either scanner is connected to the computer as a USB scanner (I can still scan from terminal).
Why is my PHP script unable to access the USB scanner(s) but $USER is able to?
I started this question at work, but now I am at home, so I will display my attempt to access the Brother MFC-9840CDW USB scanner from my PHP script.
Here is the snippet of PHP code that I am using to scan:
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");}
The PHP script works for the network scanner(s) but does not work for the USB scanner(s).
If I select either of the USB scanners (currently MFC-9840CDW) and run the script, then the file /var/log/apache2/error.log shows:
scanimage: open of device brother3:bus6;dev1 failed: Invalid argument
The question arises: Does the device brother3:bus6;dev1
exist?
Here is what scanimage --list-devices
shows when entered in the terminal at home (where MFC-9840CDW is):
[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
To demonstrate that the USB scanner(s) work for $USER, I enter the following command in the terminal:
scanimage --test -d 'brother3:bus6;dev1'
which shows:
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
To demonstrate that user www-data cannot access the USB scanner(s), I enter the following command in the terminal:
sudo -u www-data scanimage --test -d 'brother3:bus6;dev1'
which shows:
scanimage: open of device brother3:bus6;dev1 failed: Invalid argument
` and backticks for blocks of code. Use Markdown code format - select the block and click the 'code' button (or indent four spaces per line). – halfer Dec 11 '14 at 23:59