$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

Leave A Comment

Recommended Posts

在原文件名前加上前缀并实现文件的批量重命名

要在原文件名前加上前缀并实现文件的批量重命名,你可以根据你所使用的操作系统选择合适的脚本语言来编写脚本。以下是在不同操作系统上实现这一功能的示例: 在 Windows 上使用 PowerShell 在 macOS/Linux 上使用 Shell 脚本 在 Python 中使用 os 模块 注意事项 将上述脚本中的 folder_path 或 $folderPath 替换为你的文件夹路径,将 prefix 替换为你想要添加的前缀,然后运行脚本即可。

blueidea