I have a problem when I want to download a file, in this case Excel. I found the code on the Internet, when I paste it I get an error in the header .
I've searched for other codes, but apparently they still have problems in the header. It works that by clicking on a button you must download an Excel template so that it can be filled and then loaded. When loading the file I have no problems. My Excel file has locked cells, I do not know if that influences.
This is the post code of the button
if ( isset( $_POST[ 'descargar' ] ) ) {
$file= 'plantilla_proyectosLuces.xlsx';
if(is_file($file))
{
$filename="Plantilla_Productos.xlsx";//nombre que se la dara al descargar
//header("Content-disposition: attachment; filename='descarga.xlsx'");
//header("Content-type: application/vnd.ms-excel");
header("Content-Type: application/force-download");
//header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"\n");
readfile($file);
}
else
{
die("Error: no se encontro el archivo a descargar");
}
}
and this is the screen where I get the errors although I do not know why I get those characters