upload.js 467 B

1234567891011121314151617181920212223
  1. const url = 'chatserver.php?do=upload'
  2. const form = document.querySelector('form')
  3. form.addEventListener('submit', (e) => {
  4. e.preventDefault()
  5. const files = document.querySelector('[type=file]').files
  6. const formData = new FormData()
  7. for (let i = 0; i < files.length; i++) {
  8. let file = files[i]
  9. formData.append('files[]', file)
  10. }
  11. fetch(url, {
  12. method: 'POST',
  13. body: formData,
  14. }).then((response) => {
  15. console.log(response)
  16. })
  17. })