-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.php
More file actions
33 lines (27 loc) · 782 Bytes
/
source.php
File metadata and controls
33 lines (27 loc) · 782 Bytes
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
<?php
// include database connection
include "conn.php";
$id = $_GET['id'];
// select the image
$query = "select * from images WHERE id=?";
$stmt = $con->prepare( $query );
// bind the id of the image you want to select
$stmt->bindParam(1, $_GET['id']);
$stmt->execute();
// to verify if a record is found
$num = $stmt->rowCount();
if( $num ){
// if found
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// specify header with content type,
// you can do header("Content-type: image/jpg"); for jpg,
// header("Content-type: image/gif"); for gif, etc.
header("Content-type: image/jpg");
//display the image data
print $row['data'];
exit;
}else{
//if no image found with the given id,
//load/query your default image here
}
?>