PHPWord

PHPWord

/ 0 评 / 0

   1. 模板渲染值

        为避免留下变量,所有的变量都默认赋值为空

   2. 下载时header配置

        $agent = $_SERVER["HTTP_USER_AGENT"];
        if (preg_match("/MSIE/", $agent)) {
                $filename = urlencode($filename);
                $filename = str_replace("+", "%20", $filename); // 替换空格
                $attachment = "Content-Disposition: attachment; filename=\"
                {$filename}\"; charset=UTF-8";
        } else if (preg_match("/Firefox/", $agent)) {
                $attachment = 'Content-Disposition: attachment; filename*="utf-8\'
                \'' . $filename . '"';
        } else {
                $attachment = "Content-Disposition: attachment; 
                filename=\"{$filename}\"; charset=UTF-8";
        }

        Header("Content-type: application/octet-stream");
        Header("Accept-Ranges: bytes");
        header("Content-Length: " . filesize($fileDirName));
        header($attachment);
        readfile($fileDirName);
            注:header未配置时使用officeWord打开会提示内容有问题,引导修复