Hello everyone I am processing a txt file on the server using PHP
$file = fopen("archivos/llaves/keyusuario.txt", "w");
fwrite($file, 'Tu llave de usuario es: 651651651651651651');
fclose($file);
I am saving the txt in a folder on the server, now I want that txt to be downloaded in the client browser, I have tried the following using the absolute path:
$rutaArchivo = __DIR__."archivos/llaves/keyusuario.txt";
$NombreArchivo = basename($rutaArchivo);
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=$nombreArchivo");
# Leer el archivo y sacarlo al navegador
readfile($rutaArchivo);
However, at the end of the processing the file is successfully generated in the server folder, but the download is not carried out, I would greatly appreciate your help, thank you very much in advance
Try this:
Explanation:
because $FileName does not exist, it was $FileName