-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
72 lines (51 loc) · 1.64 KB
/
example.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
require_once 'GoogleCloudPrint.php';
session_start();
include "check.php";
//print_r($output);
function update_db($new_id){
// making connection with db
$conn = database_connection();
if($conn) {
//echo "Connection successful";
$new_sql = 'UPDATE insta_print SET print = "true" WHERE img_id ='."'$new_id'" ;
$pro = $conn->prepare($new_sql);
$pro->execute();
echo 'print done';
} else {
echo "DataBase connection error";
}
}
// Create object
$gcp = new GoogleCloudPrint();
$gcp->setAuthToken($_SESSION['accessToken']);
$printers = $gcp->getPrinters();
$printerid = "";
if(count($printers)==0) {
echo "Could not get printers";
//exit;
}
else {
//Define Printer
$printerid = $printers[0]['id']; // Pass id of any printer to be used for print
//$printerid = "Enter the printer ID manually if it doesn't work";
// Send document to the printer
for($k=0;$k<count($output);$k++){
$new_data = explode("#&", $output[$k]);
$img_url = $new_data[1];
$img_id = $new_data[0];
//$img_url = "https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/e15/11189553_828112557266632_991049624_n.jpg";
$resarray = $gcp->sendPrintToPrinter($printerid, "hashtag pull", $img_url, "image/jpeg");
if($resarray['status']==true) {
echo "Document has been sent to printer and should print shortly.";
update_db($img_id);
}
else {
echo "An error occured while printing the doc. Error code:".$resarray['errorcode']." Message:".$resarray['errormessage'];
}
}
}
?>
<!-- Keep Running the job for every 15 seconds -->
<!-- Set a CRON on server side for automatic running -->
<meta http-equiv="refresh" content="15" />