Erlaubte Dateitypen in ein Array gepackt
This commit is contained in:
parent
bf1182be54
commit
394a770a26
@ -1,5 +1,7 @@
|
|||||||
dropzone = document.getElementById('dropzone');
|
dropzone = document.getElementById('dropzone');
|
||||||
|
|
||||||
|
filetypes = ['image/png', 'image/jpeg', 'image/gif'];
|
||||||
|
|
||||||
dropzone.addEventListener('dragover', function(e) {
|
dropzone.addEventListener('dragover', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.classList.remove('inactive');
|
this.classList.remove('inactive');
|
||||||
@ -28,7 +30,7 @@ dropzone.addEventListener('click', function(e) {
|
|||||||
|
|
||||||
input.onchange = function(e) {
|
input.onchange = function(e) {
|
||||||
file = e.target.files[0];
|
file = e.target.files[0];
|
||||||
if(file.type == 'image/png' || file.type == 'image/jpeg' || file.type == 'image/gif') {
|
if(filetypes.includes(file.type)) {
|
||||||
upload(e.target.files[0]);
|
upload(e.target.files[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +43,7 @@ dropzone.addEventListener('drop', function(e) {
|
|||||||
this.classList.add('inactive');
|
this.classList.add('inactive');
|
||||||
|
|
||||||
file = e.dataTransfer.files[0];
|
file = e.dataTransfer.files[0];
|
||||||
if(file.type == 'image/png' || file.type == 'image/jpeg' || file.type == 'image/gif') {
|
if(filetypes.includes(file.type)) {
|
||||||
upload(e.dataTransfer.files[0]);
|
upload(e.dataTransfer.files[0]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -10,11 +10,13 @@ if(!is_dir($datadir)) {
|
|||||||
mkdir($datadir);
|
mkdir($datadir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$extensions = ['jpg', 'jpeg', 'png', 'gif'];
|
||||||
|
|
||||||
if(isset($_FILES['upload'])) {
|
if(isset($_FILES['upload'])) {
|
||||||
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
|
$extension = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
|
||||||
$extension = strtolower($extension);
|
$extension = strtolower($extension);
|
||||||
|
|
||||||
if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png' || $extension == 'gif') {
|
if(in_array($extension, $extensions)) {
|
||||||
$filename = generate_filename($length) . '.' . $extension;
|
$filename = generate_filename($length) . '.' . $extension;
|
||||||
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
|
move_uploaded_file($_FILES['upload']['tmp_name'], $datadir . '/' . $filename);
|
||||||
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
|
echo json_encode(['datadir' => $datadir, 'filename' => $filename]);
|
||||||
|
Loading…
Reference in New Issue
Block a user