So I have a Php function in a form for file upload and I want to force people, that want to upload files, to log in. So if someone clicks on upload, an like in-window-pop-up comes up and he is forced to log himself in, or the upload will be canceled.
How do I do that?
index.html
<!DOCTYPE HTML>
<html>
<head>
<title> File-Upload </title>
<link style="text/css" rel="stylesheet" href="design.css"/>
</head>
<body>
<div class="form">
<form action="upload.php" method="post" enctype="multipart/form-data">
<input class="select" type="file" name="datei"><br>
<input class="upload" type="submit" value="Hochladen">
</form>
</div>
</body>
</html>
upload.php
<?php
$upload_folder = 'uploads/';
$filename = pathinfo($_FILES['datei']['name'], PATHINFO_FILENAME);
$extension = strtolower(pathinfo($_FILES['datei']['name'], PATHINFO_EXTENSION));
$allowed_extensions = array('png', 'jpg', 'jpeg', 'gif', 'zip', 'rar', 'txt');
if(!in_array($extension, $allowed_extensions)) {
die("Ungültige Dateiendung. Nur png, jpg, jpeg, gif, zip, rar und txt-Dateien sind erlaubt");
}
$max_size = 1000*1024; //500 KB
if($_FILES['datei']['size'] > $max_size) {
die("Bitte keine Dateien größer 1000kb hochladen");
}
$new_path = $upload_folder.$filename.'.'.$extension;
if(file_exists($new_path)) {
$id = 1;
do {
$new_path = $upload_folder.$filename.'_'.$id.'.'.$extension;
$id++;
} while(file_exists($new_path));
}
move_uploaded_file($_FILES['datei']['tmp_name'], $new_path);
echo 'Bild erfolgreich hochgeladen: <a href="'.$new_path.'">'.$new_path.'</a>';
?>
I'm sorry for the German, but I think you can imagine what that would be in English.