-
Notifications
You must be signed in to change notification settings - Fork 1
/
handleLectureDownload.php
91 lines (57 loc) · 2.08 KB
/
handleLectureDownload.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
ob_start();
$con = new mysqli("localhost", "root", "", "learning_management_system");
/*if(isset($_GET['id'])){
$id = $_GET['id'];
$stat = $con->prepare("SELECT * from lecture where StudentID = $StdID and AssignmentNO = $AssNo);
// $stat->bind_param(1,$id);
$stat->execute();
$data = $stat->fetch();
// $file = 'upload/'.$data['lecturefileName'];
if(file_exists($file)){
// header('Content-Description: '.$data )
header('Content-Type: application/octet-stream');
header('Content-Description: File-Transfer');
header('Content-Disposition: attachement; filename=' . basename($filepath));
header('Expires : 0');
header('Cache-Control: must-revalidate');
header('Pragma: Public');
header('Content-Length:' .filesize('upload/' . $file['lecturefileName']));
readfile('download/' . $file['lecturefileName']);
mysqli_query($con,$updatQuery);
exit;
}else{
echo "<script>alert('error! ');</script>";
}
}*/
if(isset($_GET['id']))
{
$id = $_GET['id'];
$sql = "SELECT * FROM lecture WHERE CourseCode = $id";
$result = mysqli_query($con, $sql) or die( mysqli_error($con));
$file = mysqli_fetch_assoc($result);
$filepath = 'upload/' .$file['lecturefileName'];
if(file_exists($filepath))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filepath).$file);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
flush(); // Flush system output buffer
readfile($filepath);
die();
} else {
http_response_code(404);
die();
}
// header('Content-Length:' .filesize('upload/' . $file['lecturefileName']));
// readfile($filepath);
// mysqli_query($con,$updatQuery);
// exit;
// }
// }
}
?>