I got.
Html
<div id="multiple_upload">
<input type="hidden" id="arquivos" name="arquivos" onChange="alert(this.value)" />
<input type="file" multiple id="fotos" name="fotos[]" />
<div id="message">Selecionar fotos</div>
<div id="lista"></div>
</div>
In this case, I send the images after selected and removed through the variable $arquivos
of $_POST
generated a array
php
Here is the generation in Jquery:
var arquivos = new Array();
$(function(){
$('#fotos').on('change',function() {
var id = $(this).attr('id');
var totalFiles = $(this).get(0).files.length;
if(totalFiles == 0) {
$('#message').text('Selecionar Fotos' );
}
if ( totalFiles > 1) {
$('#message').text( totalFiles+' arquivos selecionados' );
} else {
$('#message').text( totalFiles+' arquivo selecionado' );
}
var htm='<ol>';
for (var i=0; i < totalFiles; i++) {
var c = (i % 2 == 0) ? 'item_white' : 'item_grey';
var arquivo = $(this).get(0).files[i];
var fileV = new readFileView(arquivo, i);
arquivos.push(arquivo);
htm += '<li class="'+c+'"><div class="box-images"><img class="item elevate-image" data-img="'+i+'" data-id="'+id+'" border="0"></div><span>'+arquivo.name+'</span> <a href="javascript:removeFile('+i+',\''+id+'\')" class="remove">x</a></li>'+"\n";
}
htm += '</ol>';
$('#lista').html(htm);
$('#arquivos').val(arrayParaString(arquivos)); /*Aqui eu populo o campo do form id="arquivos" com um array trazido de arrayParaString*/
});
});
arrayParaString:
function arrayParaString (array) {
i = 0;
string = "";
while (array[i]) {
string += array[i].name + '|';
i++;
}
string = string.substring(0, string.length - 1);
return string;
}
only with the name of the images then compare the $_POST["arquivos"]
with the $_FILES["fotos"]
and the one in $_FILES["fotos"]
that has in the $_POST["arquivos"]
i create an array only with them using the method below:
Php
public function arrayFotos($array1, $array2) {
$novasFotos= array();
if(is_array($array1) && count($array1) > 0) {
$i = 0;
foreach($array1 as $value1) {
foreach($array2["name"] as $key =>$value2) {
if ($value1 == $value2) {
//print $value1." - ".$value2."<br>";
if ( $array2["error"][$key] == 0) {
$novasFotos[$i]["name"] = $array2["name"][$key];
$novasFotos[$i]["type"] = $array2["type"][$key];
$novasFotos[$i]["tmp_name"] = $array2["tmp_name"][$key];
$novasFotos[$i]["error"] = $array2["error"][$key];
$novasFotos[$i]["size"] = $array2["size"][$key];
}
$i++;
break;
}
}
}
}
return $novasFotos;
}
How are you getting the data in php, because the function of removing the image in javascript removes it from html, but the various in js still gets the images
– Rodolfo Oliveira
that’s right, see the answer I posted!
– Carlos Rocha
And there friend! Mark your answer as right. Abs!
– Sam