通用企业网站系统V3.0、Web项目开发,B2B/B2C电子商务系统开发,软件开发,网站建设,网页设计,UI设计。|
php中UTF-8编码和中文文件下载的问题
filelist.php内容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body>
<?php $files=dir("./"); $i=-1; while(false!==($filename=$files->read())){ if(($filename=='.')||($filename=='..')){continue;} $filename=iconv('gb2312','utf-8',$filename); ?> <a href="download.php?filename=<?php print "$filename";?>"><?php print "$filename";?></a> <br> <?php } ?> </body> </html> download.php内容如下:
<?php
header("Content-Type:text/html;charset=utf-8"); $filename=$_GET["filename"]; $filename=iconv('utf-8','gb2312',$filename); header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); header('Content-Disposition: attachment; filename="' . $filename . '"'); $file = fopen($filename,"r"); echo fread($file,filesize($filename)); fclose($file); ?> |
CopyRight