|
php文件重命名下载代码示例
Bata1.0、基础代码(file_exists仅支持本地,还有下载时文件名乱码问题)
Bata2.0、解决中文名显示乱码问题(但还是仅支持服务器本地)
- //$down_url=$server_name.$renamefile_url.'/'.$renamefile_name; //file_exists仅支持本地
- $down_url=$renamefile_url.'/'.$renamefile_name;
- //$sourcefile_name = iconv("UTF-8",'GBK',$sourcefile_name);
- $sourcefile_name = urlencode($sourcefile_name);
- $sourcefile_name = str_replace("+", "%20", $sourcefile_name);
-
-
-
- if(file_exists($down_url)){
-
- $ua = $_SERVER["HTTP_USER_AGENT"];
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
-
- //header('Content-Disposition: attachment; filename='.basename($sourcefile_name));
-
- if (preg_match("/MSIE/", $ua)) {
- header('Content-Disposition: attachment; filename="' . $sourcefile_name . '"');
- } else if (preg_match("/Firefox/", $ua)) {
- header('Content-Disposition: attachment; filename*="utf8\'\'' . $sourcefile_name . '"');
- } else {
- header('Content-Disposition: attachment; filename="' . $sourcefile_name . '"');
- }
-
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- header('Content-Length: ' . filesize($down_url));
- ob_clean();
- flush();
- readfile($down_url);
- exit;
- }
- else{
- echo '文件目录不存在';
- }
|
|
|