mirror of
https://github.com/anatolykopyl/file-directory.git
synced 2026-03-26 12:54:30 +00:00
File upload
This commit is contained in:
40
index.php
40
index.php
@@ -14,39 +14,15 @@
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row my-5">
|
||||
<h1 class="col">Загрузки: 📥 </h1>
|
||||
<div class="col text-right">
|
||||
<?php
|
||||
session_start();
|
||||
//session_unset();
|
||||
<h1 class="col">Файлы: 📥 </h1>
|
||||
</div>
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
|
||||
echo '<p class="mt-3">Авторизован</p>';
|
||||
} else {
|
||||
echo '<button class="btn btn-light mt-2" data-toggle="dropdown">Авторизоваться </button>
|
||||
<div class="dropdown-menu dropdown-menu-right dropdown-menu-lg-left w-50">
|
||||
<form class="px-4 py-3" method="post" action="login.php">
|
||||
<div class="form-group">
|
||||
<label for="password">Пароль</label>
|
||||
<input type="password" class="form-control" name="password" placeholder="Password">
|
||||
</div>
|
||||
<input type="submit" class="btn btn-primary col-auto" value="Войти">
|
||||
<a class="col-auto" data-toggle="collapse" href="#collapseGetPass" role="button">Узнать пароль</a>
|
||||
</form>
|
||||
<div class="collapse" id="collapseGetPass">
|
||||
<form class="px-4 py-3" method="post" action="sendpass.php">
|
||||
<div class="form-group">
|
||||
<label for="inputEmail">На какой адрес выслать пароль</label>
|
||||
<input type="email" class="form-control" name="inputEmail" placeholder="Введите почту">
|
||||
</div>
|
||||
<input type="submit" class="btn btn-primary col-auto" value="Отправить">
|
||||
</form>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<label for="upload" class="w-100">
|
||||
<div class="shadow rounded card-block m-5 border p-5 text-center">
|
||||
Drop files here to upload
|
||||
</div>
|
||||
</label>
|
||||
<input id="upload" type="file" class="d-none">
|
||||
|
||||
<div class="list-group shadow rounded">
|
||||
<?php
|
||||
@@ -142,7 +118,7 @@
|
||||
echo "<div class='collapse container-fluid border-top border-secondary text-center m-2' id='collapse-" . $filetag . "'><img class='border mt-3' src='files/" . $filename . "'></div>\n";
|
||||
}
|
||||
}
|
||||
echo "<span class='col-1 border-secondary my-n3 delete-button' data-file=" . $filename . ">🗑</span>";
|
||||
echo "<span class='col-1 border-secondary my-n3 delete-button' data-file=" . urlencode($filename) . ">🗑</span>";
|
||||
echo "</span></span>\n";
|
||||
}
|
||||
}
|
||||
|
||||
10
login.php
10
login.php
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
$password = $_POST['password'];
|
||||
|
||||
if ($password == "pass") {
|
||||
session_start();
|
||||
$_SESSION['loggedin'] = true;
|
||||
}
|
||||
|
||||
header('Location: index.php');
|
||||
?>
|
||||
8
main.js
8
main.js
@@ -15,3 +15,11 @@ buttons.forEach((button) => {
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
const fileInput = document.getElementById('upload');
|
||||
fileInput.addEventListener('change', async function (event) {
|
||||
const file = event.target.files[0];
|
||||
let formData = new FormData();
|
||||
formData.append("file", file);
|
||||
fetch('upload.php', { method: "POST", body: formData });
|
||||
});
|
||||
13
sendpass.php
13
sendpass.php
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
$to = $_POST['inputEmail'];
|
||||
$subject = 'the subject';
|
||||
$message = 'hello';
|
||||
$headers = array(
|
||||
'From' => 'no-reply@radner.ru',
|
||||
'X-Mailer' => 'PHP/' . phpversion()
|
||||
);
|
||||
|
||||
mail($to, $subject, $message, $headers);
|
||||
|
||||
header('Location: index.php');
|
||||
?>
|
||||
20
upload.php
Normal file
20
upload.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
if (($_FILES['file']['name'] != "")) {
|
||||
// Where the file is going to be stored
|
||||
$target_dir = "files/";
|
||||
$file = $_FILES['file']['name'];
|
||||
$path = pathinfo($file);
|
||||
$filename = $path['filename'];
|
||||
$ext = $path['extension'];
|
||||
$temp_name = $_FILES['file']['tmp_name'];
|
||||
$path_filename_ext = $target_dir.$filename.".".$ext;
|
||||
|
||||
// Check if file already exists
|
||||
if (file_exists($path_filename_ext)) {
|
||||
echo "Sorry, file already exists.";
|
||||
}else{
|
||||
move_uploaded_file($temp_name,$path_filename_ext);
|
||||
echo "Congratulations! File Uploaded Successfully.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user