-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload.php
More file actions
26 lines (25 loc) · 991 Bytes
/
Download.php
File metadata and controls
26 lines (25 loc) · 991 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
<?php
include 'Connection.php';
if(isset($_GET['ID'])){
$ID= $_GET['ID'];
$query = "SELECT * FROM circulardb WHERE ID=$ID";
$result = $conn->query($query) or die($conn->error);
$file = mysqli_fetch_assoc($result);
$file_name = $file['FILE'];
$fileDestination = ("uploads/$file_name");
if (file_exists($fileDestination)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($fileDestination));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileDestination));
readfile($fileDestination);
// Now update downloads count
$newCount = $file['downloads'] + 1;
$updateQuery = "UPDATE files SET downloads=$newCount WHERE ID=$ID";
mysqli_query($conn, $updateQuery);
exit;
}
}