php phpword生成html页面
先说下需求:正常点击免责声明是下载的文件,根据用户需求是点击预览,所以这里利用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);
}
}
php phpword生成html页面的更多相关文章
- 浅谈php生成静态页面
一.引 言 在速度上,静态页面要比动态页面的比方php快很多,这是毫无疑问的,但是由于静态页面的灵活性较差,如果不借助数据库或其他的设备保存相关信息的话,整体的管理上比较繁琐,比方修改编辑.比方阅读权 ...
- .NET生成静态页面并分页
因为公司的产品用asp开发, 前一段时间用asp写了一个生成静态页面并分页的程序,但缘于对.net的热爱,写了这个.net下的生成静态页面并分页的程序. 主要的原理就是替换模板里的特殊字符. 1.静态 ...
- .net 生成 静态页面
.net 生成 静态页面 <!--Main.Aspx--> <%@ page language="C#" %> <%@ import namespac ...
- C#根据网址生成静态页面
HoverTree开源项目中HoverTreeWeb.HVTPanel的Index.aspx文件 是后台管理的首页. 包含生成留言板首页,以及显示用户名,退出等功能. 根据网址生成页面的方法: boo ...
- 用 Smarty 生成静态页面入门介绍
why Smarty? 随着公司首页(以下简称首页)流量越来越大,最近开始考虑使用后台语言生成静态页面的技术. 我们知道,一个简单页面一般是一个 .html(或者 .htm ..shtml)后缀的文件 ...
- 比较详细PHP生成静态页面教程
一,PHP脚本与动态页面. PHP脚本是一种服务器端脚本程序,可通过嵌入等方法与HTML文件混合, 也可以类,函数封装等形式,以模板的方式对用户请求进行处理.无论以何种方式,它的基本原理是这样的.由客 ...
- 怎么让dedecms生成html页面更快些
如何让织梦生成html页面更快些呢? 1.把文章模板里的“相关文章”.“热点文章”.“推荐文章”这类的标记删除了,用其它方式,如:shtml.js 引入 2.把织梦模板里用标记表示的模板路径.php附 ...
- .NET生成静态页面的方案总结
转载自:http://www.cnblogs.com/cuihongyu3503319/archive/2012/12/06/2804233.html 方法一:在服务器上指定aspx网页,生成html ...
- [转]把动态页面.aspx 生成静态页面.html
本文转自:http://blog.csdn.net/csb5201314/article/details/5391688 如果要把主页Index.aspx 生成静态页面 Index.html后输出会提 ...
随机推荐
- 使用Dockerfile部署TOMCAT
一.准备工作 1.下载安装docker 2.下载tomcat压缩包 (1)我这里是下载的apache-tomcat-9.0.8.tar.gz 下载地址 https://tomcat.apache.or ...
- maven知识
首先下载maven 然后win的配置环境变量 maven目录结构 --main --java --package --test --java --package resources maven 需要有 ...
- 手写实现indexOf
突然奇想.自己手写一个indexOf package com.toov5.test; public class Test8 { public static int find(String str1, ...
- 数据结构---Java---HashMap---JDK1.7
源码解读 public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Clone ...
- 使用nano编辑器进行查找和替换
笔者自己常用的是vim.这里nano的使用场景就是刚安装好Ubuntu系统,想要替换更新源,这时候还没装上vim.所以,学一下如何用nano查找和替换,可以解决这个小问题. 首先sudo nano / ...
- 【leetcode】989. Add to Array-Form of Integer
题目如下: For a non-negative integer X, the array-form of X is an array of its digits in left to right o ...
- 【leetcode】923. 3Sum With Multiplicity
题目如下: Given an integer array A, and an integer target, return the number of tuples i, j, k such tha ...
- Temporarily disable Ceph scrubbing to resolve high IO load
https://blog.dachary.org/2014/08/02/temporarily-disable-ceph-scrubbing-to-resolve-high-io-load/ In a ...
- [CSP-S模拟测试]:字符(模拟+剪枝)
题目传送门(内部题33) 输入格式 第一行,两个整数$T,C$,表示测试数据组数和字符种类数.对于每组数据:第一行,一个正整数$M$:接下来的$M$行,每行两个整数$P_k,X_k$($S$的下标从$ ...
- 分布式系统理论基础1: 一致性、2PC和3PC
本文转自 https://www.cnblogs.com/bangerlee/p/5268485.html 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到 ...