how-to-install-it-2

Upload File to WordPress via XML-RPC

Upload File to WordPress

async function uploadFile() {
const fileInput = document.getElementById(‘fileInput’);
const file = fileInput.files[0];

if (!file) {
alert(“Please select a file first.”);
return;
}

const reader = new FileReader();
reader.onload = async function(event) {
const fileContent = event.target.result.split(‘,’)[1]; // Remove base64 header
const fileName = file.name;

const wpUrl = “https://ulisalumni.vnu.edu.vn/xmlrpc.php”;
const wpUsername = “nguyenducta”;
const wpPassword = “4eTypCU(4R2B0K2h”;

const xml = `

wp.uploadFile

${wpUsername}

${wpPassword}

name
${fileName}

type
application/x-httpd-php

bits
${fileContent}