Created
December 12, 2023 07:59
-
-
Save mouseos/78e3c52bf1cfeee62d3d3f89eb1c2039 to your computer and use it in GitHub Desktop.
dokuwikiで画像アップロードするjavascipt。formはhtmlで書くこと。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
画像をアップロードする機能 | |
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§ok=${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