-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresubmit-upload.php
184 lines (155 loc) · 7.87 KB
/
resubmit-upload.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
session_start();
include('php/mysqli.php');
if(isset($_FILES['userfile']))
{
pre($_FILES['userfile']);
$error_array=array(
0=>'There is no error. File uploaded with success',
1=> 'The uploaded file size exceeds the upload_max directive in php.ini',
2=>'The uploaded file size exceeds the MAX_FILE_SIZE specified in html form',
3=> 'The uploaded file was partially uploaded',
4=>'No file was uploaded',
6=>'Missing a temporary folder ',
7=>'Failed to write file to the disk',
8=>'A PHP extension stopped the file upload'
);
$extensions=array("jpg","jpeg","pdf","doc","docx","txt","png");
$query19="Select * from tbl_lib_books where book_id='".$_POST['book_id']."' and user_id='".$_SESSION['User']."'";
$res19=$connection->query($query19);
$error;
if(!$res19)
{
// echo $_POST['book_id'].' '.$_SESSION['User'];
echo 'USer and Book uploaded don\'t match try again';
$error=1;
echo '-'.$error;
}
else{
$temp=$res19->fetch_object();
$book_req=$temp;
$sem_id=$temp->sem_id;
$query19="Select * from tbl_lib_flag where flag_id='".$temp->first_flag_id."' and status_of_approval='APPROVED'" ;
$res19=$connection->query($query19);
if(!$res19){
echo 'Looks like the Faculty is yet to approve your request Error.Bill not uploaded';
$error=1;
echo '-'.$error;
}
else{
$query19="Insert into tbl_lib_resubmit_bills values ('".$temp->book_id."', '".$temp->bill_id."')";
$res19=$connection->query($query19);
if(!$res19)
{
echo 'Error in resubmitting bills Try again '.$connection->error ;
$error=1;
echo '-'.$error;
die();
}
$query20="INSERT INTO tbl_lib_bills(book_id, bill_no, bill_date, amount) values ('".$_POST['book_id']."','".$_POST['BNumber']."','".$_POST['Bdate']."','".$_POST['BAmount']."'); ";
$res20=$connection->query($query20);
if(!$res20)
{
echo 'Error in adding bills Try again '.$connection->error;
$error=1;
echo '-'.$error;
}
else{
$insertid=$connection->insert_id;
$query20="UPDATE tbl_lib_books SET bill_id='".$insertid."' where book_id='".$_POST['book_id']."'";
$res20=$connection->query($query20);
if(!$res20)
{
echo 'bill_id not added in book table';
$error=1;
echo '-'.$error;
}
else{
$loc='bills/';
$counter=0;
$query21="Select * from tbl_lib_semester where sem_id='".$sem_id."'";
$res21=$connection->query($query21);
if(!$res21)
{
echo 'Error in fetching sem of student ';
$error=1;
echo '-'.$error;
}
else{
$temp2=$res21->fetch_object();
$loc=$loc.'/'.$temp2->sem_details.'/';
if(!file_exists($loc))
{
mkdir($loc);
echo $loc;
}
if(!file_exists($loc.$_SESSION['User']))
{
mkdir($loc.$_SESSION['User']);
// echo 'USer';
}
$loc=$loc.$_SESSION['User'].'/';
if(!file_exists($loc.$insertid))
{
mkdir($loc.$insertid);
// echo 'USer';
}
$loc=$loc.$insertid.'/';
$arr=$_FILES['userfile'];
if($arr['error'])
{
echo $arr['name'].'- '.$error_array[$arr['error']].'<br> ';
}
else{
$ext=explode('.',$arr['name']);
$ext=end($ext);
$ext=strtolower($ext);
print_r( $arr);
if(!in_array($ext,$extensions))
{
echo $arr['name'].'- '.'Invalide file extension'.'<br> ';
$error=1;
echo '-'.$error;
}
else{
$filename=$_POST['book_id'].'-'.microtime(true).'-'.$counter;
$counter++;
move_uploaded_file($arr['tmp_name'],$loc.$filename.'.'.$ext);
echo $arr['name'].'-'.$error_array[$arr['error']].'<br>' ;
}
}
}
$query20="UPDATE tbl_lib_bills SET bill_location='".$loc."' where book_id='".$_POST['book_id']."' and bill_id='".$insertid."'";
$es20=$connection->query($query20);
if(!$res20)
{
echo $connection->error;
$error=1;
echo '-'.$error;
}
else{
echo '-'.$error;
}
$query20="UPDATE tbl_lib_flag SET status_of_approval='PENDING' where status_of_approval='RESUBMIT'
and book_id='".$_POST['book_id']."' ";
$es20=$connection->query($query20);
if(!$res20)
{
echo $connection->error;
$error=1;
echo '-'.$error;
die();
}
}
}
}
}
}
function pre($array)
{
echo '<pre>';
print_r( $array);
echo '</pre>';
}
$connection->close();
?>