0
這裏我有一些代碼,它的確如它所說和下載,但是隻下載一個白色的空白空文件,並且我試圖使用這一個Wordpress並且必須沒有插件。這個腳本可以工作,但不會將任何信息下載到PDF文檔上,它只是一個白色的空白頁面,代碼中,尋找一個解決方案來將Wordpress文章添加到文檔中,這裏是鏈接和代碼,理想情況下我希望它下載執行鏈接的頁面。下載PHP/HTML/CSS到PDF文檔
HTML鏈接
<a href="http://www.WEBSITE.com/wp-content/themes/the-theme/download.php?download_file=some_file.pdf">Download file</a>
的download.php
<?php
ignore_user_abort(true);
$path = ""; // change the path to fit your websites document structure
$dl_file = preg_replace("([^\w\s\d\-_~,;:\[\]\(\].]|[\.]{2,})", '', $_GET['download_file']); // simple file name validation
$fullPath = $path.$dl_file;
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a file download
break;
// add more headers for other content types here
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
break;
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>
它下載文件,但它是一個空白的pdf,我也看了看路徑,但它只在空白時下載,如果它有一個結構崩潰並給出多個錯誤 – user3348182 2014-10-30 14:34:19