I have the following function that sends an Excel file to a controller but the problem is that I can't get it to receive it.
The function is as follows:
function Articuloconexcel(){
var file = $('#files')[0].files[0]
var data = new FormData();
data.append('archivo',file);
var url = 'WEB-INF/Controllers/Aceptacion/Controler_excel.php';
$.ajax
({
url:url,
type:'POST',
contentType:false,
data:data,
processData:false,
cache:false
});
}
I tried to receive the file in the following way:
<?php
$archivo = $_FILES['excel']['name'];
$tipo = $_FILES['excel']['type'];
$destino = "cop_".$archivo;//Le agregamos un prefijo para identificarlo el archivo cargado
if (copy($_FILES['excel']['tmp_name'],$destino)) echo "Archivo Cargado Con Éxito";
else echo "Error Al Cargar el Archivo";
But it only gives me the error message, how could I make it receive the file correctly?
You don't have to use destination, you have to use move_file_upload function indicating source and destination. Only in this way will you be able to work with the Excel file.
You would have:
More info in the documentation: Move_upload_file