-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.php
51 lines (47 loc) · 1.15 KB
/
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
<?php
include_once 'dbconnect.php';
if(isset($_POST['btn-upload']))
{
$info=$_POST['info'];
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="images/uploads/";
// new file size in KB
$new_size = $file_size/1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,info,type,size) VALUES('$final_file','$info','$file_type','$new_size')";
mysqli_query($bd,$sql);
?>
<script>
alert('successfully uploaded');
window.location.href='uploadnotice.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='uploadnotice.php?fail';
</script>
<?php
}
}
else{
?>
<script>
alert('Upload File Of Size less Than 3MB');
window.location.href='uploadnotice.php?fail';
</script>
<?php
}
?>