4
I need to download a file .xls
that is in a Mysql database, but I need to save it with the original name.
Can someone help me?
I can upload it easily. I need to download it.
include_once 'db.php';
$download = mysql_query("SELECT formResolucao FROM tbconfiguracoes");
$nome = mysql_result($download, 0, "nome");
$tipo = mysql_result($download, 0, "tipo");
$conteudo = mysql_result($download, 0, "conteudo");
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: filesize($conteudo)');
header('Content-Type: $tipo');
header("Content-Disposition: attachment; filename=$nome");
The problem is that the download does not happen?
– rray
Even low, but comes corrupted.
– Rodrigo Mota Sousa
Remove that line:
header('Content-Type: text/html; charset=utf-8');
must be playing some html in the downloaded file.– rray
Thanks. I changed what you said and modified some things here. I’ll include the code here. include_once 'db.php'; $download = mysql_query("SELECT * FROM tbannexes Where seqAnexo = 20"); $name = mysql_result($download, 0, "endname"); $type = mysql_result($download, 0, "filename"); $content = mysql_result($download, 0, "arqAnexo"); //header('Content-Type: text/html; charset=utf-8'); header('Content-Type: filesize($content)'); header('Content-Type: $type'); header("Content-Disposition: Attachment; filename=$name"); Return ($content);
– Rodrigo Mota Sousa
Actually downloaded but came zeroed. He brought the correct name and such, but comes with 0 bytes.
– Rodrigo Mota Sousa
After header, of an echo on
$conteudo
.– rray
Thank you very much, it worked, it lacked the echo even.
– Rodrigo Mota Sousa
@Rodrigomotasousa Don’t want to post the complete solution as an answer? It can help future visitors.
– bfavaretto