-
Notifications
You must be signed in to change notification settings - Fork 3
/
ref_get.php
executable file
·55 lines (49 loc) · 1.76 KB
/
ref_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
<?php
// Make sure an R_id was passed
if(isset($_GET['R_id'])) {
// Get the id
$id = intval($_GET['R_id']);
// Make sure it is a valid id
if($id <= 0) {
die('The ID is invalid!');
}
else {
// Connect to the database
$dbLink = new mysqli('localhost', 'root', '', 'Nitcq');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
// Query for all Reference notes that satisfy the given condition
$query = "
SELECT `ref_name`,`Type`,`size`,`Subject`,`Notes`
FROM `Reference_Notes`
WHERE `R_id` = {$id}";
$result = $dbLink->query($query);
if($result) {
// Make sure the result is valid
if($result->num_rows == 1) {
// Get the row
$row = mysqli_fetch_assoc($result);
// Print headers
header("Content-Type: ". $row['Type']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['ref_name']);
// Print data
echo $row['Notes'];
}
else {
echo 'Error! No image exists with that ID.';
}
// Free the mysqli resources
@mysqli_free_result($result);
}
else {
echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
}
@mysqli_close($dbLink);
}
}
else {
echo 'Error! No ID was passed.';
}
?>