-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
64 lines (55 loc) · 1.28 KB
/
upload.php
File metadata and controls
64 lines (55 loc) · 1.28 KB
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
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-upload']))
{
for($i=0; $i<count($file = $_FILES['file']['name']); $i++) {
$file = $_FILES['file']['name'][$i];
$file_loc = $_FILES['file']['tmp_name'][$i];
$file_size = $_FILES['file']['size'][$i];
$file_type = $_FILES['file']['type'][$i];
$folder="uploads/";
if ($file_loc == "") {
?>
<script>
alert('Please select files!');
window.location.href='index.php?fail';
</script>
<?php
}else{
if ($file_size > 41943040) {
?>
<script>
alert('File size exceed 40MB!');
window.location.href='index.php?fail';
</script>
<?php
}
else{
$new_size = $file_size/1024;
$new_file_name = strtolower($file);
$final_file=str_replace('','',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,type,size) VALUES('$final_file','$file_type','$new_size')";
mysql_query($sql);
?>
<script>
alert('successfully uploaded');
window.location.href='index.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='index.php?fail';
</script>
<?php
}
}
}
}
}
?>