0
<script type="text/javascript">
var nomess = [];
function handleFileSelect() {
var output = document.getElementById("resultt");
arquivos = $("#imagem").prop("files");
var nomes = $.map(arquivos, function(val) { return val.name; });
//new
var filesStr = "";
for (let i = 0; i < arquivos.length; i++) {
var extensao = nomes[i].split('.').pop().toLowerCase();
if(extensao == "doc" || extensao == "docx"){
icone = "http://www.programari.com.br/assets/images/icons/word.png";
}else if(extensao == "jpg" || extensao == "jpeg"){
icone = "http://www.programari.com.br/assets/images/icons/jpg.png";
}else if(extensao == "png"){
icone = "http://www.programari.com.br/assets/images/icons/png.png";
}else if(extensao == "xml"){
icone = "http://www.programari.com.br/assets/images/icons/xml.png";
}else if(extensao == "gif"){
icone = "http://www.programari.com.br/assets/images/icons/gif.png";
}else if(extensao == "pdf"){
icone = "http://www.programari.com.br/assets/images/icons/pdf.png";
}else if(extensao == "bmp"){
icone = "http://www.programari.com.br/assets/images/icons/bmp.png";
}else if(extensao == "txt"){
icone = "http://www.programari.com.br/assets/images/icons/txt.png";
}else if(extensao == "xlsx" || extensao == "xls"){
icone = "http://www.programari.com.br/assets/images/icons/xls.png";
}else{
icone = "http://www.programari.com.br/assets/images/icons/file.png";
}
nomess.push(arquivos[i]);
filesStr += "<li>" + arquivos[i].name + "<button onclick='removeLiy(this)' style='background-color:white; border:0'><i class='fas fa-trash' style='color:red; font-size: 24px; padding: 8px 0px 0px 3px;'></i></button><img src='"+icone+"' height='24' />" + "</li>";
}
console.log(nomess);
document.getElementById("imagem").value = '';
document.getElementById("result").innerHTML += filesStr;
document.getElementById('imagem').addEventListener('change', handleFileSelect, true);
}
function removeLiy(e) {
nomess = nomess.filter(function(imagem) {
return imagem.name !== e.parentNode.innerHTML.split("<button")[0];
//alert(nomess);
console.log(nomess);
//var aqui ='aqui';
})
e.parentNode.parentNode.removeChild(e.parentNode);
console.log(nomess);
//var aqui ='aqui nao';
var myJSON = JSON.stringify(arquivos);
document.getElementById("result").innerHTML = myJSON;
console.debug('myJSON');
}
document.getElementById('imagem').addEventListener('change', handleFileSelect, false);
</script>
I’m trying to capture the Arrays
Javascript and move on to a input hidden
of my form to submit it and send to a file PHP for upload.
Welcome Richard Barcelos, you could add the code you are using?
– RXSD
hello buddy, yes. I’ll put.
– Richard Barcelos
Richard, I saw that your code does a lot of things, you could detail your problem better so I can understand?
– RXSD
Of course friend, I have a form with fields: textarea, date field and multiple file type field. When I click on add files it adds and creates an array with.pushname. This is ok, add and delete, My problem is to take the generated array with the images and send by clicking the send button of the form.
– Richard Barcelos
when I give a console.log(namess) it shows the image I put... I need to take this array names and put inside the image input file for when I send the form it send those selected files
– Richard Barcelos
in this other post I ask the same question: https://answall.com/questions/362273/como-fazer-o-campo-input-file-multiple-em-uma-segunda-sele%C3%A7%C3%A3o-maintain-os-arquivos/362515#362515 ?
– Richard Barcelos
You want to capture an array of files and add to the value of a input Hidden, that’s it?
– RXSD
I don’t know if that would be the best way. Because I don’t know if the Hidden input could pass me the data for processing the images in the php file that the form action sends... along with the other fields I already have inside the <form>
– Richard Barcelos
– Richard Barcelos
Did you understand?
– Richard Barcelos
You want to do this because the input file is out of form?
– Sam
If you have in the form the files are already sent as array, no?
– Sam
input file is inside the form. I select for example a file from one folder, after another and so it goes to the end I want to get everyone I selected and stored in the javascript array, by clicking on the send I want to send all attachments.
– Richard Barcelos
Are in the form most are not being sent no..
– Richard Barcelos
@sam You would know how to pass this array of images to the form submission??
– Richard Barcelos
Take a look in this answer. I think you get the input name.
– Sam
@Sam tried here and did not equal to pick up the name of the input
– Richard Barcelos