Skip to content

Instantly share code, notes, and snippets.

@Utkarsh-vishnoi
Created June 23, 2020 04:16
Show Gist options
  • Save Utkarsh-vishnoi/4d2f8301e87d2857ab1ae5d97e46ef2b to your computer and use it in GitHub Desktop.
Save Utkarsh-vishnoi/4d2f8301e87d2857ab1ae5d97e46ef2b to your computer and use it in GitHub Desktop.
<?php
$valid_passwords = array ("username" => "password");
$valid_users = array_keys($valid_passwords);
$user = $_SERVER['PHP_AUTH_USER'] ?: '' ;
$pass = $_SERVER['PHP_AUTH_PW'] ?: '';
$validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
if (!$validated) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die ("Not authorized");
}
if(isset($_FILES['upload'])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["upload"]["name"]);
$target_file_ext = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if($target_file_ext == 'gz' || $target_file_ext == 'tgz' || $target_file_ext == 'tar') {
if($_FILES["upload"]["size"] <= 50000000) {
if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["upload"]["name"]). " has been uploaded.";
}
else {
echo "Sorry, there was an error uploading your file.";
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment