Eu criei uma function de download mas ela ta corrompendo os arquivos e eu não consigo encontrar o motivo! Baixa normalmente, mas quando eu vou abrir o arquivo ele informa que o arquivo ta em um formato desconhecido ou danificado.
public function download($token, $renomear) {
$local_file = 'download/' . $token . '.zip';
$download_file = $renomear . '.zip';
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
if (file_exists($local_file) && is_file($local_file)) {
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($local_file));
header('Content-Disposition: filename=' . $download_file);
header('Connection: Close');
flush();
$file = fopen($local_file, "r");
while (!feof($file)) {
// send the current file part to the browser
print fread($file, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
fclose($file);
} else {
$pdo = new PDO\Database();
$insertStatement = $pdo->insert(array(
"item_token" => $token,
"valor" => "Erro: o arquivo não existe!"
))
->into("file_log");
$insertStatement->execute();
header("Refresh: 0");
die();
}
}