rWanBoy 's BLOG

[Welcome to my Blog]记录着点点滴滴,保存着许许多多

Advanced RAR Password Recovery1.53的注册码 ARPR-83296730531875-CBBVYBXFEXDEVPMB

 Advanced RAR Password Recovery1.53的注册码 ARPR-83296730531875-CBBVYBXFEXDEVPMB

下面这段代码是不能够返回正确值的代码,无论文件是否在都返回不在:

 

下面这段代码是不能够返回正确值的代码,无论文件是否在都返回不在:

1
2
3
4
5
6
<?php;
$file="/attachment/21/0/中文.rar";
$newfile = dirname(__FILE__).$file;
 
echo file_exists($newfile);
?>

经过测试之后,增加了一句将UTF8编码转换为GB2312编码的语句,就可以正确判断了:

这样看来,程序必须得这样写才能支持所有主流浏览器:

这样看来,程序必须得这样写才能支持所有主流浏览器:

<?php

$ua = $_SERVER["HTTP_USER_AGENT"];// $_SERVER["HTTP_USER_AGENT"]在IE中显示为:
// Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

$filename = "中文 文件名.txt";
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);

header('Content-Type: application/octet-stream');//if (preg_match("/MSIE/", $ua)) {        
//兼容IE11if(preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)){
	header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
} else if (preg_match("/Firefox/", $ua)) {
	header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"');
} else {
	header('Content-Disposition: attachment; filename="' . $filename . '"');
}

print 'ABC';?>


«1»

Powered By Z-Blog 2.3 Avengers Build 180518

Copyright(c) www.rWanBoy.Cn studios 2007-2024. All Rights Reserved.浙ICP备12023569号-1