-
Notifications
You must be signed in to change notification settings - Fork 0
/
student-upload-document-action.php
executable file
·67 lines (61 loc) · 2.24 KB
/
student-upload-document-action.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
<?php
include 'connection.php';
session_start();
$role = $_SESSION['sess_userrole'];
$email = $_SESSION['sess_email'];
if(!isset($email) || $role!="student"){
header('Location: index.php?err=2');
}
if(isset($_POST['submit'])){
$student_id = $_POST['student'];
$doc_type = $_POST['doc-type'];
$file_name = rand(1000,100000)."-".$_FILES['file']['name'];
$new_file_name = strtolower($file_name);
$final_file=str_replace(' ','-',$new_file_name);
$temp_name = $_FILES['file']['tmp_name'];
$file_ext = explode('.', $file_name);
$file_fname = explode('.', $file_name);
$file_size = $_FILES['file']['size'];
$file_error = $_FILES['file']['error'];
$allowed = array('pdf','doc');
if($file_error === 0){
if(isset($file_name) and !empty($file_name)){
$location="documents/";
//$root = getcwd();
if(move_uploaded_file($temp_name,$location.$final_file)){
echo "Uploaded";
$sql="INSERT INTO student_document(student_id,document_type_id,file) VALUES('$student_id','$doc_type','$final_file')";
mysqli_query($conn, $sql);
header('Location: ' . $_SERVER['HTTP_REFERER']);
//header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
?>
<script>
//window.location.href='student-upload-document.php?success';
</script>
<?php
}else{
?>
<script>
window.location.href='student-upload-document.php?failed';
</script>
<?php
}
}else{
?>
<script>
//alert('No file');
window.location.href='student-upload-document.php?none';
</script>
<?php
}
}else{
?>
<script>
//alert('There is a problem with file');
window.location.href='student-upload-document.php?problem';
</script>
<?php
}
}else{
echo "Totally OUT";
}