Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Eduneri

Como fazer download do .pdf sem que abra no browser?

Recommended Posts

E aí galera, beleza?

 

Gostaria de saber se alguém sabe alguma coisa sobre sobre como fazer o download de um .pdf sem que abra o browser... somente faça o download.

 

Um grande abraço

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deixa eu explicar melhor...

 

Tem o arquivo .pdf no servidor, daí o usuário ao clicar, gostaria que ele fizesse o download ao invés do browser abrir o arquivo para ele.

 

Isto é possível?

 

Grande abraço,

Compartilhar este post


Link para o post
Compartilhar em outros sites

Exemplo #1 Download dialog

 

If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the » Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?>
Fonte: http://br2.php.net/header

 

http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif

 

[]s

Beraldo

Compartilhar este post


Link para o post
Compartilhar em outros sites

Intaum Beraldo...

 

Coloquei a função header como você explico, porém qdo faz o download o arquivo vem corrompido... já se peço simplesmente abrir pelo browser e depois salvá-lo na maquina, fica certinho o arquivo... o que vcs acham q pode estar acontecendo:

 

<?

$id = $_GET['id'];
$artigo = $id.".pdf";

header('Content-type: application/pdf');

header("Content-Disposition: attachment; filename=".basename($artigo).";");

header("Content-Transfer-Encoding: binary");

header("Content-Length: ".filesize($artigo));

readfile('original.pdf');

?>

Obrigado pela ajuda pessoal

Compartilhar este post


Link para o post
Compartilhar em outros sites

Já havia tentando... porém tentei novamente devido a sua opinião... porém tbém não deu certo...

 

Obrigado pela ajuda!!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Alguém??????????

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, eu testei aki esse codigo

 

<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf
readfile('original.pdf');
?>

e ele pediu pra baixar normalmente...experimenta copiar o codigo da pagina do header so mudando o nome do arquivo...

Compartilhar este post


Link para o post
Compartilhar em outros sites

<?php

 

$base_dir = realpath( '.' );

$str = '\\';

strpos( $base_dir, $str ) ? $base_slash = $str : $base_slash = "/";

 

$fileName = 'arquivo.pdf';

$fileLocalPath = $base_dir . $base_slash . $fileName;

 

$fileSize = filesize( $fileLocalPath );

 

header("Content-Type: application/force-download");

header("Content-Length: " . $fileSize );

header("Content-disposition: filename=" . $fileName );

header("Pragma: no-cache");

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");

header("Expires: 0");

readfile( $fileLocalPath );

 

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

E aí galera, beleza?

 

Mais uma vez eu encomodando vcs novamente...

 

Não deu certo... eu tento fazer o download, ele faz, porém o arquivo fica corrompido...

 

e se pedir para abrir no brownser, funciona certinho... o q será?

 

 

o código q useri foi:

<?

$id = $_GET['id'];

$base_dir	= realpath( '.' );
$str			 = '\\';
strpos( $base_dir, $str ) ?	$base_slash = $str : $base_slash = "/";

$fileName	  = $id.'.pdf';
$fileLocalPath = $base_dir . $base_slash . $fileName;

$fileSize = filesize( $fileLocalPath );

header("Content-Type: application/force-download");
header("Content-Length: " . $fileSize );
header("Content-disposition: filename=" . $fileName );
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
readfile( $fileLocalPath );

?>

Muito obrigado pela ajuda...

Compartilhar este post


Link para o post
Compartilhar em outros sites

faça um debug

 

antes do header

 

// for debug
echo '<br>filename: ' . $fileName;

echo '<br>fileLocalPath : ' . $fileLocalPath;

echo '<br>fileSize : ' . $fileSize;

exit; // interrompe o script

header("Content-Type: application/force-download");
header("Content-Length: " . $fileSi ...

faça o teste e poste aqui o resultado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.