0

I'm just wondering if this is actually possible, if it is not, why?

  • add files via input type file multiple true
  • files get stored in array of "FilesList" inside javascript
  • when user is done selecting images, click upload
  • upload all images in that stored array in javascript

var storedFiles = [];

$("#inputFileId").on('change', function() {
  if ($(this)[0].files) {
    for (var i = 0; i < $(this)[0].files.length; i++) {
      storedFiles.push($(this)[0].files[i]);
    }
  }
});

$("#inputSubmitId").click(function() {
  // add this storedFiles to an input is possible?
  // like $("#input").val = storedFiles;
  console.log(storedFiles);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>select any amount of images, how many times you want to</p>
<input type="file" multiple="true" id="inputFileId" />
<input type="submit" id="inputSubmitId" />

3
  • Yes, that's all possible. Do you have a specific issue? Commented Feb 15, 2018 at 17:00
  • How it's possible? yeah, i have the following error trying to $(this)[0].files = storedFiles Failed to set the 'files' property on 'HTMLInputElement': The provided value is not of type 'FileList'. typeof storedFiles = object Commented Feb 15, 2018 at 17:01
  • 1
    That's because you're attempting to set the value of an input type="file" control - you cannot do that. You will need to upload your aggregated file array via AJAX for this to work Commented Feb 15, 2018 at 17:04

1 Answer 1

1

You can't upload files via js..It is an client side language...You need to use php or any cliend side language for that.... Here it is a website which includes it all:W3 Schools

Use multiple tag to get multiple images at a time and then using php store this images....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.