php实现office文档转成pdf预览方法

$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();
移动文件是防止因读写执行权限限制导致执行失败

你可能感兴趣的:(PHP,phpnotes,php,pdf,office)