Redirect page after uploading file for download

Asked

Viewed 812 times

2

I have a page that when uploaded sends a pdf file to download. How do I after the file is sent to the browser, redirect the page?

I’m sending the file so do so:

// Dados do arquivo
$file = "Arquivos/documento.pdf";

// Configuramos os headers que serão enviados para o browser
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

// Limpa o conteúdo interno do buffer
ob_clean();
flush();

// Envia o arquivo para o cliente
readfile($file);

// Descarrega o conteúdo interno do buffer
ob_end_flush();

1 answer

4


I don’t know the context, but maybe if you do this page that forces the download to open in a target="_Blank" already solve the download. To redirect would be to treat the click with JS, like this:

<a href="baixa_pdf.php" target="_blank" download onclick="javascript:location.href='redir.php'">Baixar</a>

Browser other questions tagged

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