$filetype = array(".docx",".doc",".xlsx",".xls",".pptx",".ppt",".jpg",".png",".pdf"); //文件类型
$tempFile = "/uploads/".$log["attachment"]; //$log["attachment"]为文件地址;
$url = str_replace($filetype,"",$tempFile).".pdf"; //替换文件后缀
//header('Location: '.$url);
//die();
$tempFile = "/tmp/".basename($log["attachment"]); //临时文件地址
copy("www.xxx.com/".$log["attachment"],$tempFile); //移动文件
exec("unoconv -f pdf ".$tempFile); //文件转pdf
$pdf = str_replace($filetype,"",$tempFile).".pdf";
header("Content-type:application/pdf");
// 文件将被称为 downloaded.pdf
//header("Content-Disposition:attachment;filename=downloaded.pdf");
// PDF 源在 original.pdf 中
readfile($pdf);
//$url = "/uploads/".$log["attachment"];
die();
原文链接:https://blog.csdn.net/leesin2011/article/details/53317362