Download Blob Mysql file

Asked

Viewed 1,326 times

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?

  • 1

    Even low, but comes corrupted.

  • 1

    Remove that line: header('Content-Type: text/html; charset=utf-8'); must be playing some html in the downloaded file.

  • 1

    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);

  • Actually downloaded but came zeroed. He brought the correct name and such, but comes with 0 bytes.

  • 1

    After header, of an echo on $conteudo.

  • Thank you very much, it worked, it lacked the echo even.

  • 2

    @Rodrigomotasousa Don’t want to post the complete solution as an answer? It can help future visitors.

Show 3 more comments

1 answer

1

php file has to look like this:

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: application/vnd.ms-excel; name='excel'");

header("Content-Disposition: filename=".$nome.".xls");

header("Pragma: no-cache");



echo $conteudo;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.