-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRemotePrint.php
More file actions
55 lines (49 loc) · 1.3 KB
/
RemotePrint.php
File metadata and controls
55 lines (49 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Created by JetBrains PhpStorm.
* User: Harikrishnan
* Date: 5/10/14
* Time: 4:28 PM
* To change this template use File | Settings | File Templates.
*/
class RemotePrint
{
public $ip;
public $port;
private $error = 'Error. ';
public function init()
{
}
public function test_connection()
{
//telnet ip port
if(0){
$this->error = 'Connection to remote printer failed. Please check IP or Port';
}
}
public function test_exec()
{
//check exec enabled or not
if(!function_exists('exec')){
$this->error = 'exec() function is disabled in your php.ini, please enable it.';
}
}
public function print_data($data)
{
if($data == ''){
return 'Nothing to print. Data is empty';
}
$this->test_connection();
$this->test_exec();
if('Error. ' === $this->error){
$command = '/bin/echo '.escapeshellarg($data).' | /usr/bin/lpr -l -H '.$this->ip.':'.$this->port.' > /dev/null 2>&1';
if(exec($command, $output)){
return 'Successfully sent data to remote printer.';
}else{
return 'Error. Permission denied';
}
}else{
return $this->error;
}
}
}