Problem with file download in php

Asked

Viewed 381 times

0

am with the following file download code:

set_time_limit(0); // Define o tempo máximo de execução em 0 para as conexões lentas

    $arquivoLocal = "../arquivo/emboss/needle/Resultado/$resultado"; // caminho absoluto do arquivo

    // Verifica se o arquivo não existe
    if (!file_exists($arquivoLocal)) {
        echo "Arquivo não encontrado.";
        exit;
    }

    header('Content-Description: File Transfer');
    header('Content-Disposition: attachment; filename="'.$resultado.'"');
    header('Content-Type: application/octet-stream');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($arquivoLocal));
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Expires: 0');

    readfile($arquivoLocal);

The problem I am is that when I click send, the file that is coming to download is the page view that I am not the one that I put in $arquivoLocal, along with the header where the filesize( $arquivoLocal) shows the download size of the view too, I made a print_r(filesize($filefileLocal) before the header and in this print I get the right file size. The problem I don’t understand is because the readfile($arquivolocal) is not downloading the correct file?

  • Elaborate the question a little better please.

  • If the file is too large it may cause problems in the function readfile. Related issue in Soen

  • If you go through the IF, it’s because the file exists. If the correct file is not coming to download, maybe some server permission issue, then it is returning to download the page instead of the file. I did tests here, including with 10MB files, and worked perfectly.

  • Would it be permission issue in apache ? Strange in header('Content-Length: ' . filesize($fileLocal)); already give the view size and not the file I want.

  • I performed an echo "<a href='.. /file/Emboss/Needle/Result/hba_human.Needle' download>download not open it</a>"; and the download file is correct it would be something with the readfile or headers not picking up the correct file?

  • I opened the download view and with it is coming at the end the download file inside the view file

Show 1 more comment
No answers

Browser other questions tagged

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