I have the following html
with two buttons type file
<label>Adjuntar Recibo de gas escaneado en JPG o PDF</label>
<input type='file' name='archivoReciboGas' id='archivoReciboGas' />
<br></br>
<label>Adjuntar Certificado libertad y tradicion en JPG o PDF</label>
<input type='file' name='archivoCertiLibertad' id='archivoCertiLibertad' />
Here is the ajax
that the file sends but only of 1
button, that is to say only that of the cedula, (Upload the cedula)
var inputFileCedula = document.getElementById('archivoCedula');
var file = inputFileCedula.files[0];
var data = new FormData();
data.append('archivo',file);
var url = 'php/subir_cedula.php';
$.ajax
({
url:url,
type:'POST',
contentType:false,
data:data,
processData:false,
cache:false
});
Here the upload_edula.php that saves the file
<?php
//PHP QUE SUBE LA CEDULA Y LA GUARDA
require 'conectar_bd.php';
$return = Array('ok'=>TRUE);
$upload_folder ='../archivos_subidos';
$nombre_archivo = $_FILES['archivo']['name'];
$tipo_archivo = $_FILES['archivo']['type'];
$tamano_archivo = $_FILES['archivo']['size'];
$tmp_archivo = $_FILES['archivo']['tmp_name'];
$archivador = $upload_folder . '/' . $nombre_archivo;
if (!move_uploaded_file($tmp_archivo, $archivador)) {
$return = Array('ok' => FALSE, 'msg' => "Ocurrio un error al subir el archivo. No pudo guardarse.", 'status' => 'error');
}
echo json_encode($return);
?>
In what way could you take advantage of the same Ajax
to also send the file that is selected from the other button, ie both at the same time.
Currently I have to create a AJAX
and a PHP
for each button separately