2014-02-14 131 views
-1

我已經創建了一個頁面,您可以在「textarea」中寫入文本,然後當您單擊下載時,將該文件下載爲.txt文件。我對其他擴展做了同樣的事情,並且工作正常。但它不會與.PDF一起使用,我沒有讀過任何東西。這裏是我用於.PDF下載的片段:PHP標頭下載PDF

<?php 

if($fileFormat == ".pdf"){ 

$content = $_POST['text']; 
$name = stripslashes($_POST['name']); 
$nameAndExt = $name.".pdf"; 
print strip_tags($content); 

header('Content-type: application/pdf'); 
header('Content-Disposition: attachment; filename="'.$nameAndExt.'"'); 
header('Content-Transfer-Encoding: binary '); 
} 

?> 

我很感謝任何answear,謝謝!

+0

我認爲這隻適用於修改後的標題。你需要一個像這樣的html2pdf轉換器插件:http://sourceforge.net/projects/html2fpdf/ – GoE

+0

好的,我會查找它,謝謝! –

回答

0
// hold the filename for use elsewhere so you don't have to append .pdf every time 
$filename = "$id.pdf"; 

// create the file 
$pdf->output($filename); 

// set up the headers 
header("Content-Description: File Transfer"); 
header("Content-disposition: attachment; filename={$filename}"); 
header("Content-Type: application/pdf"); 
header("Content-Transfer-Encoding: binary"); 
header('Content-Length: ' . filesize($file)); 

// push the buffer to the client and exit 
ob_clean(); 
flush(); 

// read the file and push to the output stream 
readfile($filename); 

// remove the file from the filesystem 
unlink($filename); 
exit(); 
+0

它仍然無法正常工作,但謝謝! –

0

我會推薦一個像TCPDF這樣的類,參見http://www.tcpdf.org/。我用它幾次,這是相當不錯的(開源)。

+0

我會檢查一下,謝謝! –