Get file stored in Bin in MySQL

0

Live!

I'm having trouble getting my PDF file that was stored in a MySQL DB. Whenever I download it, I can not open it because it returns the message that may be corrupted.

So I store:

$docs = new Documentos();

$assunto = filter_input(INPUT_POST,'assunto');
$origem = filter_input(INPUT_POST, 'origem');
$dataEntrada = filter_input(INPUT_POST, 'dataEntrada');

$fileName = $_FILES['ficheiros']['name'];
$ficheiro_temp = $_FILES['ficheiros']['tmp_name'];
$tamanho = $_FILES['ficheiros']['size'];
$tipo = $_FILES['ficheiros']['type'];

copy($ficheiro_temp, "../upload/$fileName");

$ficheiro = file_get_contents($ficheiro_temp);
$ficheiro = addslashes($ficheiro);


$docs->setAssunto($assunto);
$docs->setDataEntrada($dataEntrada);
$docs->setOrigem($origem);
$docs->setDocName($fileName);
$docs->setTipo($tipo);
$docs->setTamanho($tamanho);
$docs->setFicheiro($ficheiro);

$docs->armazenarFicheiros();

So I download it:

foreach ($docs->verFicheiro() as $f){
        $file = $f['ficheiro'];
        $size = $f['tamanho'];
        $type = $f['tipo'];
        $name = $f['nomedocumento'];
    }

    header("Content-length: {$size}");
    header("Content-type: {$type}");
    header('Content-Disposition: attachment; filename="'.$name.'"');

    fpassthru($file);
    
asked by anonymous 08.05.2015 / 11:15

1 answer

0

There is something strange about this code for the download. You're using a foreach, but then you just send the file once. Why are you doing a foreach?

In addition, what is this Documents? A class of yours? Or an external API? Much information is missing ...

    
08.05.2015 / 11:29