how o create upload multiple picture with javadcript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how o create upload multiple picture with javadcript?

i want to create form that can upload multiple picture with javascript or c# can anyone help me?

9th Sep 2017, 2:09 PM
prg_Mohamad
prg_Mohamad - avatar
11 Answers
+ 3
IF you would store an array of all names of images, there will be no problem cause you just load up the names of images and then get them from the server. But there is no function (at least I didn't find one, there may be, but hardly belivable with JS) that get the whole directory at once. I may be wrong. So yes, you can pass a whole imageurl to a function that is present to you here, even download it from a server side, but only if you know the names of that images
9th Sep 2017, 3:08 PM
Paul
+ 7
It's not possible to get an image from user in code-playground because Sololearn don't ask for your permission to access your gallery. To get an image as input you have to use any browser.
9th Sep 2017, 2:43 PM
Ranjan Bagri
Ranjan Bagri - avatar
+ 2
ohh yes, let me guide you! do you want to load those pictures from a folder i side your project? do you know how many is there of them or you want to make something like a gallery where you can add pictures?
9th Sep 2017, 2:27 PM
Paul
+ 2
So actually in C# it is pretty simple to do. If you create a WPF application, you can create an "openFileDialog" control. Take a look at this: https://stackoverflow.com/questions/10315188/open-file-dialog-and-select-a-file-using-wpf-controls-and-c-sharp later on, you just get the Path(s) of the pictures that were choosen, and you can copy them to your file or load them up to you program and show them on the screen. If you need some brief example, let me know. In JavaScript, you mean a stand alone JS or for a website side?
9th Sep 2017, 2:40 PM
Paul
+ 2
So actually this is a simple code where you load up a img from a folder and add it to a div container: window.onload = function () { 'use strict'; var check, small_src, real_src, ref, i, img, container; container = document.getElementById(id-of-your-container); for (i = 1; i <= 1000000; i += 1) { small_src = "images/s" + i + ".jpg"; real_src = "images/" + i + ".jpg"; check = check_if_availabe(small_src); if (check) { img = document.createElement("img"); img.setAttribute("src", small_src); img.setAttribute("width", '350'); container.appendChild(img); } else { break; } } }; I use a simple solution to check if the image is in the folder. If no, the function breakes, that is why I can make the FOR loop run to 1k and this means nothing to my program. Also I load pictures that have names from 1 to x, so 1, 2, 3 and so on. If you do not have let's say 3, so 1,2,4 <- the loop will break at second image and stoploading
9th Sep 2017, 2:54 PM
Paul
+ 2
And this is the check-load function: function check_if_availabe(src) { "use strict"; var http = new XMLHttpRequest(); http.open('HEAD', src, false); http.send(); return http.status !== 404; } true means "exists", this is thy the loop just simply check that. Sorry for splitting it into two posts, hope tht helps
9th Sep 2017, 2:55 PM
Paul
+ 1
hey thanks for answering...i want to get pictures from user and put it in slider... for example he select 5 picture and when he clicked in upload button pictures will save in my solution folder and he can delete any of them if he want
9th Sep 2017, 2:31 PM
prg_Mohamad
prg_Mohamad - avatar
+ 1
i will show those picture on some page in view after that
9th Sep 2017, 2:32 PM
prg_Mohamad
prg_Mohamad - avatar
+ 1
im using aspnet mvc its backend is c# and i can use the topic you gave me tnx but how to use javascript for accessing my folder that files uploaded to and show it in my slider i mean java script thay can be used in web site
9th Sep 2017, 2:43 PM
prg_Mohamad
prg_Mohamad - avatar
+ 1
tnx paul but there is one problem in your code your file name is like 1.jpg and 2.jpg and so on is there any way to check it from imageurl and file name from folder that all pictures saved
9th Sep 2017, 3:05 PM
prg_Mohamad
prg_Mohamad - avatar
+ 1
thanks
9th Sep 2017, 3:26 PM
prg_Mohamad
prg_Mohamad - avatar