Skip to content

Instantly share code, notes, and snippets.

@mouseos
Created December 12, 2023 07:59
Show Gist options
  • Save mouseos/78e3c52bf1cfeee62d3d3f89eb1c2039 to your computer and use it in GitHub Desktop.
Save mouseos/78e3c52bf1cfeee62d3d3f89eb1c2039 to your computer and use it in GitHub Desktop.
dokuwikiで画像アップロードするjavascipt。formはhtmlで書くこと。
/*
画像をアップロードする機能
sectokに入っているトークンとcallparameterでアップロードを行うと指定してアップロード
*/
document.getElementById('uploadButton').addEventListener('click', function() {
const fileInput = document.getElementById('fileInput');
const files = fileInput.files;
// 必要なパラメーターを追加
const sectok = document.querySelector('input[name="sectok"]').value;
const call = 'mediaupload'; // callパラメーターの値
// 各ファイルを順番にアップロード
for (let i = 0; i < files.length; i++) {
const file = files[i];
const formData = new FormData();
formData.append('qqfile', file);
const url = `http://127.0.0.1/dokuwiki/lib/exe/ajax.php?=undefined&sectok=${sectok}&call=${call}`;
const headers = new Headers({
// 必要なヘッダーを追加
});
const fetchOptions = {
method: 'POST',
headers: headers,
body: formData
};
fetch(url, fetchOptions)
.then(response => {
// レスポンスの処理
console.log(response);
})
.catch(error => {
// エラー処理
console.error('Request failed', error);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment