500 * 1024 * 1024) { return false; } // Allow-list check against the FINAL extension only, case-insensitive $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); if ($extension === '' || !in_array($extension, $allowed_extensions, true)) { return false; } // Unguessable storage name. We deliberately do NOT hash file contents: // randomString(32) already guarantees uniqueness, and hashing would mean // reading the whole file into memory (up to 500 MB) for no downstream use. return randomString(32) . '.' . $extension; }