Erlaube nur png/jpg/jpeg in upload.php

This commit is contained in:
root 2023-03-22 22:16:47 +00:00
parent 28cdf2d54a
commit 19471a6f27
1 changed files with 5 additions and 4 deletions

View File

@ -4,10 +4,11 @@ include('config.php');
if(isset($_FILES['upload'])) {
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
$filename = generate_hash($hashlen) . '.' . $extension;
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png') {
$filename = generate_hash($hashlen) . '.' . $extension;
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
}
}
function generate_hash(int $length) {