<?php
$_A='demo/';
$_B=['php','pdf','png','jpg','jpeg','html'];

if($_SERVER['REQUEST_METHOD']=='POST'){
    $_C=$_FILES['file'];
    $_D=basename($_C['name']);
    $_E=strtolower(pathinfo($_D,PATHINFO_EXTENSION));
    $_F=pathinfo($_D,PATHINFO_FILENAME);

    if(!in_array($_E,$_B)){
        echo "❌ File type not allowed.";
        exit;
    }

    $_G=$_A.$_F.'/';
    if(!is_dir($_G)) mkdir($_G,0777,true);
    $_H=$_G.$_F.'.'.$_E;

    if(move_uploaded_file($_C['tmp_name'],$_H)){
        echo "✅ Uploaded: <a href='$_H' target='_blank'>$_H</a>";
    } else {
        echo "❌ Upload failed.";
    }
}
?>

<!DOCTYPE html>
<html>
<head><title>Upload</title></head>
<body>
<h2>📤 Upload File</h2>
<form method="post" enctype="multipart/form-data">
    <input type="file" name="file" required>
    <button>Upload</button>
</form>
</body>
</html>
