-
Notifications
You must be signed in to change notification settings - Fork 1
/
get.php
57 lines (50 loc) · 1.91 KB
/
get.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
<?php
//get.php
/*****************************************************
Returns the base 64 encoded string representing the full sized image
Requires
$_REQUEST['dev'] - device unique id
$_REQUEST['img'] - unique image id to match in the database
Returns JSON
code should be zero if there is no error
The id parameter will be the unique image id from the database
{"code":0, "message": "Feedback message", "id":123, "data":"base 64 encoded string representing the full size image"}
if code is something else then there is an error and no data for the image
{"code":423, "message":"error message for you" }
*****************************************************/
require_once("db.inc.php");
header("Content-Type: application/json");
if( isset( $_GET['dev'] ) && isset($_GET['img_id']) ){
//we have the device id
//Retrieve matching records for device
$dev_id = trim($_GET['dev']);
$img_id = intval($_GET['img_id']);
$sql = "SELECT img_id, full_img FROM w15_final WHERE device_id=? AND img_id=?";
$rs = $pdo->prepare($sql);
$ret = $rs->execute( array($dev_id, $img_id) );
if($ret){
//need to check if row count > 0
$count = $rs->rowCount();
if($count > 0){
$row = $rs->fetch();
//only one row so no loop
echo '{"code":0, "message":"Success", "id":';
echo $row['img_id'] . ', "data":"';
echo $row['full_img'] .'"';
echo '}';
}else{
//no matches
echo '{"code":333, "message":"No matches for this device and image reference"}';
}
}else{
//failed to run query.... error
$errorArray = $rs->errorInfo( );
echo '{"code":543, "message":"Unable to fetch data from database at this time. SQL ErrorCode: ' . $errorArray[0] . '"}';
}
}else{
//no device id provided
echo '{"code":423, "message":"Missing required parameter(s)."}';
}
exit();
$pdo = null;
?>