TCPDF解决保存中文文件名的方法

PHP使用TCPDF生成PDF文件时,如果文件名是中文会被直接过滤掉,以下是TCPDF不能保存中文文件名的解决方法:

打开tcpdf.php文件,找到output函数,大约在8467行(7554)行。

1、注释以下代码,大约在8467-8470行  或(7565-7568)行:

if ($dest[0] != 'F') {
    $name = preg_replace('/[\s]+/', '_', $name);
    $name = preg_replace('/[^a-zA-Z0-9_\.-]/', '', $name);
}

2、搜索该方法代码,替换如下代码,大约分别在8580 行。

header('Content-Disposition: attachment; filename="'.basename($name).'"'); 

替换为

header('Content-Disposition: attachment; filename="'.$name.'"');
上述代码分别在该方法的case 'I':(打印PDF)、case 'D':(下载PDF)、case 'FD':(保存到本地文件)语句中。

这样PHP使用TCPDF生成PDF文件时就可以保存为中文名称了。

猜你喜欢

转载自www.cnblogs.com/zc290987034/p/10543625.html