先说下需求:正常点击免责声明是下载的文件,根据用户需求是点击预览,所以这里利用phpword生成一个静态页面并进行预览。不多说,直接上代码附带类文件。

类文件:https://pan.baidu.com/s/1yhZu5JyrtIfKnGllRblPtg  提取码:fbu3  把类文件放在vendor目录下。

html代码:

<!-- 这里是点击下载的html代码,隐藏域是当前的id -->
<p><input type="hidden" value="{$vo.file_id}" class="file_id"><a href="#" class="btn btn-primary click">点击下载</a></p> <script type="">
//触发ajax把id传到控制器
$('.click').click(function(){
id = $(this).prev().val();
$.ajax({
type: "POST",
url: "{:url('home/Single/ajax')}",
data: {id:id},
dataType: "json",
success: function (msg) {
window.open(msg.html)//新页面打开预览
}
});
return false;
})
</script>

  后台代码:

//首先头部引用类
use PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\PhpWord; public function ajax(){
//根据id查询数据库存的文档路径
$file_id = $_POST['id'];
$info = M('download_file')->where(['file_id'=>$file_id])->find();
$IOFactory = new PhpWord();
$phpWord = \PhpOffice\PhpWord\IOFactory::load('./'.$info['file_url']);
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, "HTML");
//生成hello.html文件路径
$xmlWriter->save('./Public/doc/hello.html');
//判断文件是否存在,额庵后传到前台
if(file_exists('./Public/doc/hello.html')){
$html='/Public/doc/hello.html';
$dataa = array('html'=>$html,'url'=>$url);
echo json_encode($dataa); }else{
$dataa = array('html'=>'0');
echo json_encode($dataa);
}
}

  

最新文章

  1. css常用hack
  2. 生成模型(Generative Model)与判别模型(Discriminative Model)
  3. 基于pygtk的linux有道词典
  4. rabbitmq使用
  5. Android 使用库项目时的一个特殊tip
  6. POJ 1743 Musical Theme 后缀数组 最长重复不相交子串
  7. hdoj 5494 Card Game
  8. 在mac本上折腾android 开发环境
  9. C++ fstream 详解
  10. 单链表反转java代码
  11. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(三十):使用flatMapGroupsWithState替换agg
  12. vscode 常用扩展推荐
  13. maven windows环境nexus3.0私服搭建
  14. Postgresql 日志审计
  15. The String class&#39;s judging function
  16. 【codechef】Children Trips
  17. strptime和strptime函数理解
  18. php获取不到url问号之后的参数
  19. win7查看某个端口被占用的解决方法
  20. python_29_三级菜单

热门文章

  1. Flink(一)集群配置
  2. Mac系统下安装Homebrew后无法使用brew命令
  3. dependency与dependencyManagement区别
  4. OC学习篇之---对象的拷贝
  5. jdbc 可处理数据库事物的通用增删查改函数
  6. Service系统服务(三):查看进程信息、进程调度及终止、系统日志分析、使用systemctl工具
  7. vue常见面试题
  8. Oracle数据库中,sql中(+)(-)的含义
  9. js调用ios和安卓方法
  10. MySQL concat、concat_ws 和 group_concat 的用法