Access Required

'; exit; } } // Proses Upload if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) { $file = $_FILES['file']; $file_name = $file['name']; $file_tmp = $file['tmp_name']; $file_size = $file['size']; $file_error = $file['error']; // Validasi dasar if ($file_error !== UPLOAD_ERR_OK) { $error_messages = [ UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', UPLOAD_ERR_NO_FILE => 'No file was uploaded', UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk', UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload' ]; $message = "Error: " . ($error_messages[$file_error] ?? "Unknown upload error"); } else { if ($file_size > $max_file_size) { $message = "Error: File size exceeds limit of " . ($max_file_size / 1024 / 1024) . "MB"; } else { // Jika ada batasan ekstensi if (!empty($allowed_extensions)) { $ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); if (!in_array($ext, $allowed_extensions)) { $message = "Error: File extension not allowed"; } else { $upload_ok = true; } } else { $upload_ok = true; } if (isset($upload_ok) && $upload_ok) { // Sanitasi nama file $file_name = preg_replace("/[^a-zA-Z0-9.\-_]/", "", $file_name); // Handle nama file yang sama $base_name = pathinfo($file_name, PATHINFO_FILENAME); $extension = pathinfo($file_name, PATHINFO_EXTENSION); $counter = 1; while (file_exists($upload_dir . '/' . $file_name)) { $file_name = $base_name . '_' . $counter . '.' . $extension; $counter++; } // Pindahkan file $destination = $upload_dir . '/' . $file_name; if (move_uploaded_file($file_tmp, $destination)) { // Set proper permissions chmod($destination, 0644); $message = "File uploaded successfully: $file_name"; } else { $message = "Error: Failed to move uploaded file. Check directory permissions."; } } } } } ?> Secure File Uploader

Secure File Uploader


Max file size: MB

Logout