Reputation: 577
I have a single html input with multiple value.
<div class="form-group">
<label for="fotoVisita">Foto della visita</label><span id="erroreFotoVisita"></span>
<input type="file" class="form-control" multiple="true" accept="image/*" id="fotoVisita" name="fotoVisita[]">
</div>
To give this parameters to the server I use Ajax, and my script is something like this:
var data = new FormData(document.getElementById("formAggiungiVisita"));
jQuery.ajax({
type : "POST",
url : "scripts/Clienti/aggiungiVisita.php",
data : data,
contentType: false,
processData: false,
success : function() {
//Something
},
error : function() {
//Something
}
});
Now from PHP I'm not able to take the image and put them on my server (not MySQL).
I have the folder that I created:
if (!file_exists('../../Foto/'.$id_cliente.'/'.$data."_".$conn->insert_id)) {
mkdir('../../Foto/'.$id_cliente.'/'.$data."_".$conn->insert_id, 0777, true);
}
After that I tried many tutorial and example but none worked. 1) http://webtips.krajee.com/ajax-based-file-uploads-using-fileinput-plugin/ 2) Upload multiple images to a database from a singe fileinput
Somebody can help me here?
Upvotes: 1
Views: 3077
Reputation: 577
foreach($_FILES['fotoVisita']['tmp_name'] as $key => $tmp_name)
{
$file_name = $key.$_FILES['fotoVisita']['name'][$key];
$file_size =$_FILES['fotoVisita']['size'][$key];
$file_tmp =$_FILES['fotoVisita']['tmp_name'][$key];
$file_type=$_FILES['fotoVisita']['type'][$key];
move_uploaded_file($file_tmp,'../../Foto/'.$id_cliente.'/'.$data."_".$conn->insert_id."/".time().$file_name);
}
Solved using this code, I'm not sure what I was doing wrong. Sorry people.
Upvotes: 2