01.
<?php
02.
03.
include
(
"check_admin.php"
);
04.
error_reporting
(-1);
05.
ini_set
(
'display_errors'
, 1);
06.
$conn
= mysqli_connect(
"localhost"
,
"root"
,
"123456"
,
"project"
)
or
die
(
'ไม่สามารถ ติดต่อกับฐานข้อมูลได้<br>'
.
$conn
->error);
07.
$conn
->set_charset(
'utf8'
);
08.
$id
=isset(
$_POST
[
'id'
])?
$_POST
[
'id'
]*1:0;
09.
$sqll
=
'UPDATE phts SET numphts = numphts+1 WHERE id = '
.
$id
;
10.
$objQuery
=
$conn
->query(
$sqll
)
or
die
(
$sql
.
'<br>'
.
$conn
->error);
11.
if
(
$conn
->affected_rows<1){
12.
die
(
'Affected rows was zero'
);
13.
}
14.
$sqll
=
'SELECT * FROM `phts` WHERE `id` = '
.
$id
;
15.
$rs
=
$conn
->query(
$sqll
)
or
die
(
$sqll
.
'<br>'
.
$conn
->error);
16.
if
(
$rs
->num_rows){
17.
$r
=
$rs
->fetch_object();
18.
$content
=
file_get_contents
(
$r
->file);
19.
header(
'Content-type: pdf'
);
20.
header(
'Content-length: '
.str_len(
$content
));
21.
header(
'Content-Disposition: attachment; filename='
.
$r
->files);
22.
echo
$content
;
23.
}
else
{
24.
echo
"No Contents found"
;
25.
}