-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_file.php
220 lines (192 loc) · 6.99 KB
/
load_file.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
session_start();
if (!isset($_SESSION["username"])) {
header("location:admin_login.php");
exit;
}
include "include/connect.php";
include "include/gensettings.php";
include "user.php";
$task = $_POST['task'];
$bar_id = $_POST['bar_id'];
if ($_POST['submit']) {
$query = "SELECT * FROM barrower where bar_id = '$bar_id' ";
$result = mysql_query($query, $connect) or die("cant execute query!.....");
$newArray = mysql_fetch_array($result);
if (mysql_num_rows($result) == 0) {
$msg = "The Borrower's ID does not exists!...";
$task = "none";}
if ($task == "up") {
if ($upload_file == "on") {
if ($userfile_size > 250000) {$msg = "Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
$borrowers_pic = "false";
}
$add = "upload/$userfile_name"; // the path with the file name where the file will be stored, upload is the directory name.
if (!($userfile_type == "image/pjpeg" or $userfile_type == "image/gif")) {$msg = $msg . "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
$borrowers_pic = "false";
}
$query = "SELECT * FROM borrowers_pic where bar_id = '$bar_id' ";
$result = mysql_query($query, $connect) or die("cant execute query!.....");
$newArray = mysql_fetch_array($result);
if (mysql_num_rows($result) != 0) {
$msg = "A picture already exists...Please remove first the picture to inset new one";
} else {
if (move_uploaded_file($userfile, $add)) {
$query = "INSERT INTO borrowers_pic(bar_id,file_name,file_size,file_type) VALUES('$bar_id','$userfile_name', '$userfile_size', '$userfile_type')";
$result = mysql_query($query, $connect) or die("cant execute query!.....");
$file_id = mysql_insert_id();
$msg = "The file is already uploaded....";
} //end if
}
} // end if $upload_file is set on
else {
$msg = "You are not allowed to upload picture file!";
}
} // end if $task=upload
if ($task == "rem") {
if ($remove_file == "on") {
$query = "SELECT * FROM borrowers_pic where bar_id = '$bar_id' ";
$result = mysql_query($query, $connect) or die("cant execute query!.....");
$newArray = mysql_fetch_array($result);
if (mysql_num_rows($result) == 0) {
$msg = "No picture associated to the user is found...";
} else {
$query = "delete from borrowers_pic where bar_id = '$bar_id'";
$result = mysql_query($query, $connect) or die("cant execute query!.....");
$msg = "Picture was successfully deleted...";
}
} // end if $remove_file is on
else {
$msg = "You are not allowed to delete a picture!";
}
} //end if $task==rem
} //end if submit
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $system_title . "--" . $footer; ?></title>
<link rel="stylesheet" type="text/css" href="css/<?php echo $css; ?>" />
<SCRIPT language=javascript>
function numbersOnly(el){
el.value = el.value.replace(/[^0-9]/g, "");
}
</SCRIPT>
<script type="text/JavaScript">
<!--
function MM_openBrWindow1(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<script type="text/JavaScript">
<!--
function FormEval(){
if (document.myform.bar_id.value == ""){
alert("Please enter the Borrower's ID!");
document.myform.bar_id.focus();
return false;
}
}//-->
</script>
<script>
<!--
function hanap(){
if (document.myform.task.value == "up"){
document.myform.userfile.disabled = false;
document.myform.userfile.focus();
document.myform.bar_id.disabled = false;
}
if (document.myform.task.value == "rem"){
document.myform.userfile.disabled = true;
document.myform.bar_id.disabled = false;
document.myform.bar_id.focus();
}
}
//-->
</script>
</head>
<body >
<div class="header">
<div class="logo"><?php echo " " . $header_title; ?> </div>
<div id="Layer1"><img src="images/<?php echo $logo; ?>" width="117" height="110" />
<div id="Layer2"></div>
</div>
</div>
<div class="navbg">
<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="home.php" id="current" title="Home">Home</a></li>
<li><a href="admin.php" title="Search">Search</a></li>
<li><a href="admin_add_new.php" title="Add book">Add book</a></li>
<li><a href="barrower.php" title="Borrower">Borrower</a></li>
<li><a href="inventory.php" title="Inventory">Inventory</a></li>
<li><a href="settings.php" title="Settings">Settings</a></li>
<li><a href="help1.php" title="Help">Help</a></li>
<li><a href="logout.php" title="Logout">Logout</a></li>
</ul>
</div>
</div>
<div class="maincontent">
<div class="floatelft">
<h2><a href="barrower.php">Search borrower</a> | <?php if ($borrow_book == "on") {
echo '<a href="bar_new.php">Borrow books </a>';
} else {
echo "Borrow Book";
}
?> | <?php if ($add_borrower == "on") {
echo '<a href="create_borrower.php">Add borrower</a>';
} else {
echo "Add Borrower";
}
?> |<?php if ($show_borrower == "on") {
echo '<a href="show_borrower.php">Show borrower</a>';
} else {
echo "Show Borrower";
}
?>|<?php if (($upload_file == "on") || ($remove_file == "on")) {
echo '<a href="load_file.php">Update borrower photo</a>';
} else {
echo "Update borrower photo";
}
?>|<?php if ($uri == "admin") {
echo '<a href="pay_fee.php">Return books</a>';
} else {
echo "Return books";
}
?></h2>
<form enctype="multipart/form-data" name="myform" id="myform"action="load_file.php" method="post">
<?php echo $msg; ?><p><strong>What to do:
<select name="task" id="task" onchange="hanap()" >
<option value="up">Upload Picture</option>
<option value="rem">Remove Picture</option>
</select><br />
Enter the locaton of the picture you wish to upload...<br>
Upload this file:
<input name="userfile" type="file" />
<br />
Borrower's ID:
<input type="text" name="bar_id" id="bar_id"size="20" />
<input name="submit" id="submit" type="submit" value="Send File" class="btn" onclick="return FormEval()"/>
</strong></p>
</form>
<p>
</p>
<p> </p>
</div>
</div>
<div class="lowercontent"></div>
<div class="footer1">
<table align="center">
<tr>
<td><img src="logo/anilag systems logo 300x155 trnsparent.png" /></td>
<td> </td>
<td><img src="images/isch.gif" width="200" height="70"/></td>
</tr>
</table></div>
<div class="footer">
<?php echo $system_title; ?><br /><?php echo $footer; ?>
</div>
</body>
</html>