您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php下载文件出现乱码怎么办

2024/3/26 21:05:01发布13次查看
php下载文件出现乱码的解决方法:首先使用ob_clean()函数丢弃输出缓冲区中的内容;然后利用ob_flush()函数冲刷出输出缓冲区中的内容;最后下载文件即可。
函数介绍:
ob_clean()函数用来丢弃输出缓冲区中的内容。
ob_flush()冲刷出(送出)输出缓冲区中的内容。
(相关视频推荐:java视频教程)
解决方法:
在下载文件之前,先使用以上两个函数进行处理,然后再下载即可,这样就不会出现乱码了。
代码实现:
<?php/** * 强制下载文件 * @param string $filename 变量 * @param string $name 变量 * @return mixed */function download($filename,$name){ if ((isset($filename))&&(file_exists($filename))){ header("content-length: ".filesize($filename)); header('content-type: application/octet-stream'); header('content-disposition: attachment; filename="' . $name . '"'); ob_clean(); flush(); readfile("$filename"); } else { $info="looks like file does not exist!"; return $info; }}?>
相关推荐:php培训
以上就是php下载文件出现乱码怎么办的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product