Php - Download files by application get corrupted

Asked

Viewed 168 times

0

When downloading files or documents through my application, they successfully download, more when opening are corrupted.

//FILE DOWNLOAD

$arquivo   = 'C:/teste/arquivo.zip';

header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=" . basename($arquivo));
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Length: " . filesize($arquivo));

readfile($arquivo);
  • test the value returned by readfile, if it is returning FALSE, it has an error in reading the file.

  • If the file is too large... https://answall.com/questions/320553/problema-ao-tenta-baixararquivos-grandes/320566#320566

  • See if you have that https://answall.com/questions/192387/for%C3%A7ar-download-com-php-file-come-corrupted/192417#192417

  • I did so: ini_set ("display_errors", "1"); error_reporting (E_ALL); $file = $_GET["C:/test/1.txt"]; $type="application/txt"; header("Content-Type: ". $type); header("Content-Length: ". filesize($file); header("Content-Disposition: Attachment; filename=". basename($file)); readfile($file); Exit; (The file is small has 2kb)

  • The txt file has been downloaded.. More the content of the original file is: abcdef : <

2 answers

0

I did so:

ini_set ("display_errors",  "1"); 
    error_reporting (E_ALL);
    $arquivo = $_GET["C:/teste/1.txt"];
      $tipo="application/txt"; 

      header("Content-Type: ".$tipo);
      header("Content-Length: ".filesize($arquivo));
      header("Content-Disposition: attachment; filename=".basename($arquivo));
      readfile($arquivo);
      exit;

(The file is small has 2kb)

0

The txt file downloaded..

More the content of the original document is: abcdef

And what was downloaded when opening is: <

Browser other questions tagged

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