Skip to content

Commit 7000b3b

Browse files
committed
Initial commit
1 parent eb4f36d commit 7000b3b

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

index.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
session_start();
3+
4+
?>
5+
<!DOCTYPE html>
6+
<html>
7+
8+
<head>
9+
<meta charset="utf-8">
10+
<title>Signin Upload</title>
11+
<link rel="icon" href="favicon.png">
12+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
13+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
14+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css"
15+
integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
16+
</head>
17+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
18+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
19+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
20+
<link href="signin.css" rel="stylesheet">
21+
</head>
22+
23+
<body class="text-center">
24+
<div class="container-fluid">
25+
26+
<div class="row justify-content-center">
27+
<div class="mx-1 mt-1 card rounded">
28+
<div class="card-body">
29+
<form action="upload.php" method="post" enctype="multipart/form-data" class="form-signin">
30+
<h1 class="h3 mb-3 font-weight-normal">Please verify</h1>
31+
<label for="inputPassword" class="sr-only">Password</label>
32+
<input type="password" name="pwd" id="pwd" class="form-control" placeholder="Password" required>
33+
<label class="btn btn-primary btn-block">
34+
Browse <input type="file" name="fileToUpload" id="filetoUpload"
35+
onchange="$('#upload-file-info').html(this.files[0].name)" hidden>
36+
</label>
37+
<p class='label label-info' id="upload-file-info"></p>
38+
<p class='label label-info' id="retval"></p>
39+
<!-- <input class="btn btn-primary btn-block" type="file" name="fileToUpload" id="fileToUpload"> -->
40+
<button name="submit" class="btn btn-lg btn-primary btn-block" type="submit">Verify and upload
41+
</button>
42+
<p class="mt-5 mb-3 text-muted">&copy; 2019-2020</p>
43+
</form>
44+
</div>
45+
</div>
46+
47+
</div>
48+
</div>
49+
<?php
50+
if(isset($_SESSION['message']))
51+
{
52+
echo $_SESSION['message'];
53+
unset($_SESSION['message']);
54+
}
55+
?>
56+
</body>
57+
58+
</html>

signin.css

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
html,
2+
body {
3+
height: 100%;
4+
}
5+
6+
body {
7+
display: -ms-flexbox;
8+
display: flex;
9+
-ms-flex-align: center;
10+
align-items: center;
11+
padding-top: 40px;
12+
padding-bottom: 40px;
13+
background-color: #f5f5f5;
14+
}
15+
16+
.form-signin {
17+
width: 100%;
18+
max-width: 330px;
19+
padding: 15px;
20+
margin: auto;
21+
}
22+
.form-signin .checkbox {
23+
font-weight: 400;
24+
}
25+
.form-signin .form-control {
26+
position: relative;
27+
box-sizing: border-box;
28+
height: auto;
29+
padding: 10px;
30+
font-size: 16px;
31+
}
32+
.form-signin .form-control:focus {
33+
z-index: 2;
34+
}
35+
.form-signin input[type="email"] {
36+
margin-bottom: -1px;
37+
border-bottom-right-radius: 0;
38+
border-bottom-left-radius: 0;
39+
}
40+
.form-signin input[type="password"] {
41+
margin-bottom: 10px;
42+
border-top-left-radius: 0;
43+
border-top-right-radius: 0;
44+
}

upload.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
session_start();
3+
if (isset($_POST["submit"])) {
4+
$str = "<script>$('#retval').html('";
5+
if ($_POST['pwd'] == 'YOUR_PASSWORD_HERE') {
6+
$target_dir = "uploads/";
7+
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
8+
$uploadOk = 1;
9+
$FileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
10+
// Check if file already exists
11+
if (file_exists($target_file)) {
12+
$str .= "Sorry, file already exists.<br>";
13+
$uploadOk = 0;
14+
}
15+
// Allow certain file formats
16+
//if($FileType != "json" && $FileType != "txt" && $FileType != "html"
17+
//&& $FileType != "pdf" ) {
18+
// echo "Sorry, only xlsx,xls,and csv files are allowed.";
19+
// $uploadOk = 0;
20+
//}
21+
// Check if $uploadOk is set to 0 by an error
22+
if ($uploadOk == 0) {
23+
$str .= "Sorry, your file was not uploaded.";
24+
// if everything is ok, try to upload file
25+
} else {
26+
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
27+
$str .= "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded.";
28+
} else {
29+
$str .= "Sorry, there was an error uploading your file.";
30+
}
31+
}
32+
} else {
33+
$str .= "Invalid key";
34+
}
35+
$str .= "');</script>";
36+
$_SESSION['message'] = $str;
37+
unset($_POST);
38+
unset($_FILES);
39+
header("Location: index.php");
40+
exit;
41+
}
42+
?>

0 commit comments

Comments
 (0)