PDF İndirme düzgün çalışmıyor

3 Cevap php

Ben bir PDF indirmek için aşağıdaki kodu kullanıyorum ....

   header('Content-Type: application/pdf');
   header('Content-Disposition: attachment; filename="NewName.pdf"');
   readfile($root_path.'/full-tile-book.pdf');

Bu 13 MB dosya bulunuyor ve 130K gibi ve tabii ki sadece indirme açılamaz. Nasıl burada sorun nedir debug? Pdf benim yolum doğrudur.

3 Cevap

Ben birkaç öğe eklemek istiyorum. $ Dosya dosya adı atamak, daha sonra deneyin:

header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);

Bu, istemci doğru uzunluğunu bekleniyor, ve aralarında güzel çıktı tamponu basması sağlayacaktır.

see downloaded file perhaps have bad address use in PHP.
You can follow this tutorial for file download in PHP.

HTML headers must be sent before any output is sent to the browser. PHP uses the header function to pass raw HTML headers. For this example we're going to get the filename from the URL www.yourdomain.com/download.php?file=download.zip.

<? 
$dir="/path/to/file/";
if (isset($_REQUEST["file"])) {
    $file=$dir.$_REQUEST["file"];
    header("Content-type: application/force-download");
    header("Content-Transfer-Encoding: Binary");
    header("Content-length: ".filesize($file));
    header("Content-disposition: attachment; filename="".basename($file).""");
    readfile("$file");
} else {
    echo "No file selected";
}
 ?>

We started with setting the directory where the files to be downloaded are located in $dir. Be sure not to use in $dir. Then we checked to make sure a filename was specified in the request. If a file was specified then we set $file to the path to the file and the filename. Now that the prep work is done its time to send the file to the browser.

The first header statement tells the browser to expect a download. The next two header statements tell the browser the format of the data and the size of the file respectively. The last header statement tells the browser the name of the file. Finally the readfile statement sends the file to the browser.

More information.