<?php
$ud=__DIR__."/";$m="";$mt="";
if($_SERVER["REQUEST_METHOD"]==="POST"&&isset($_FILES["files"])){
$t=count($_FILES["files"]["name"]);$s=0;$f=0;$e=[];
for($i=0;$i<$t;$i++){if($_FILES["files"]["error"][$i]===UPLOAD_ERR_OK){
$n=basename($_FILES["files"]["name"][$i]);$d=$ud.$n;
if(!empty($_POST["sf"])){$sb=trim($_POST["sf"],"/\\");$sb=preg_replace("/[^a-zA-Z0-9_\-\/\.]/","",$sb);$sd=$ud.$sb;if(!is_dir($sd))@mkdir($sd,0755,true);$d=$sd."/".$n;}
if(file_exists($d)&&empty($_POST["ow"])){$ex=pathinfo($n,PATHINFO_EXTENSION);$b=pathinfo($n,PATHINFO_FILENAME);$c=1;while(file_exists($d)){$d=$ud.$b."_".$c.".".$ex;$c++;}}
if(move_uploaded_file($_FILES["files"]["tmp_name"][$i],$d))$s++;else{$f++;$e[]=$n;}}else{$f++;$e[]=$_FILES["files"]["name"][$i];}}
$m="Upload: {$s} ok".($f?", {$f} fail":"");$mt=$f?"warning":"success";}
?><!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Up</title>
<style>*{box-sizing:border-box;margin:0;padding:0}body{font-family:-apple-system,sans-serif;background:#0f1117;color:#e0e0e0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:20px}.c{background:#1a1d27;border-radius:16px;padding:40px;max-width:600px;width:100%;box-shadow:0 20px 60px rgba(0,0,0,.5);border:1px solid #2a2d3a}h1{font-size:24px;margin-bottom:8px;color:#fff}.sub{color:#888;font-size:13px;margin-bottom:25px}.dz{border:2px dashed #3a3d4a;border-radius:12px;padding:50px 20px;text-align:center;cursor:pointer;transition:.3s;margin-bottom:20px}.dz:hover,.dz.ov{border-color:#4a9eff;background:rgba(74,158,255,.05)}.dz .ic{font-size:48px;margin-bottom:12px}.dz p{color:#aaa;font-size:14px}.dz .br{color:#4a9eff}.fl{margin:15px 0;max-height:200px;overflow-y:auto}.fi{display:flex;justify-content:space-between;align-items:center;padding:8px 12px;background:#22253a;border-radius:8px;margin-bottom:6px;font-size:13px}.fi .n{color:#ccc;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.fi .s{color:#888;margin-left:10px}.fi .x{color:#ff5555;cursor:pointer;margin-left:10px;font-weight:bold;font-size:16px}.opt{display:flex;gap:12px;margin-bottom:20px;flex-wrap:wrap}.opt input[type=text]{flex:1;min-width:150px;padding:10px 14px;background:#22253a;border:1px solid #3a3d4a;border-radius:8px;color:#e0e0e0;font-size:13px;outline:0}.opt label{display:flex;align-items:center;gap:6px;font-size:13px;color:#aaa;cursor:pointer}.btn{width:100%;padding:14px;border:none;border-radius:10px;font-size:16px;font-weight:600;cursor:pointer;background:linear-gradient(135deg,#4a9eff,#2d7dd2);color:#fff}.btn:disabled{opacity:.4;cursor:not-allowed}.msg{padding:12px 16px;border-radius:8px;margin-bottom:20px;font-size:14px}.msg.success{background:rgba(40,167,69,.15);border:1px solid #28a745;color:#5fdd77}.msg.warning{background:rgba(255,193,7,.15);border:1px solid #ffc107;color:#ffdd57}</style></head>
<body><div class="c"><h1>&#128228; Uploader</h1><div class="sub"><?php echo htmlspecialchars($_SERVER["HTTP_HOST"]??"");?></div>
<?php if($m):?><div class="msg <?php echo $mt;?>"><?php echo htmlspecialchars($m);?></div><?php endif;?>
<form method="post" enctype="multipart/form-data" id="uf"><div class="dz" id="dz"><div class="ic">&#128193;</div><p>Drag & drop or <span class="br">browse</span></p><input type="file" name="files[]" id="fi" multiple style="display:none"></div>
<div class="fl" id="fl"></div><div class="opt"><input type="text" name="sf" placeholder="Subfolder (optional)"><label><input type="checkbox" name="ow" value="1"> Overwrite</label></div>
<button type="submit" class="btn" id="ub" disabled>Upload</button></form></div>
<script>const dz=document.getElementById("dz"),fi=document.getElementById("fi"),fl=document.getElementById("fl"),ub=document.getElementById("ub");let dt=new DataTransfer;dz.onclick=()=>fi.click();dz.ondragover=e=>{e.preventDefault();dz.classList.add("ov")};dz.ondragleave=()=>dz.classList.remove("ov");dz.ondrop=e=>{e.preventDefault();dz.classList.remove("ov");for(let f of e.dataTransfer.files)dt.items.add(f);fi.files=dt.files;rf()};fi.onchange=()=>{for(let f of fi.files)dt.items.add(f);fi.files=dt.files;rf()};function rf(){fl.innerHTML="";for(let i=0;i<dt.files.length;i++){const f=dt.files[i],d=document.createElement("div");d.className="fi";d.innerHTML='<span class="n">'+f.name+'</span><span class="s">'+fs(f.size)+'</span><span class="x" data-i="'+i+'">&times;</span>';fl.appendChild(d)}ub.disabled=!dt.files.length;fl.querySelectorAll(".x").forEach(b=>b.onclick=function(){dt.items.remove(+this.dataset.i);fi.files=dt.files;rf()})}function fs(b){return b<1024?b+" B":b<1048576?(b/1024).toFixed(1)+" KB":(b/1048576).toFixed(1)+" MB"}</script></body></html>