<?php
require_once '../../util/util.php';
// header("Location: Content-type: application/json;charset=UTF-8");
/**
* file_path 中必须得是全部是英文
* @param $file_path
*/
function download_file($file_path)
{
// 强制转码成 gbk 防止文件名下载的时候出现错误 (但是要小心 Linux 服务器 , 其系统级编码是 utf-8)
$file_path = iconv('utf-8', 'gbk', $file_path);
$filename = realpath($file_path);
$start = str_right_index($file_path, '.');
$extend = substr($file_path, $start + 1);
$date = date("Ymd");
Header("Content-type:application/octet-stream,charset=utf-8");
Header("Accept-Ranges:bytes");
Header("Accept-Length:" . filesize($filename));
header("Content-Disposition:attachment;filename=$date.$extend");
echo file_get_contents($filename);
}
if (isset($_GET['file_path'])) {
download_file($_GET['file_path']);
// echo iconv('utf-8', 'gbk', $_GET['file_path']);
} else {
echo '你不应该来到这里', '<br/>';
}
// http://localhost:63342/php_blog_sys/back_page/controller/download_file.php?_ijt=1012ocgc982ffr1qkifbtlvm&file_path=test_rar_1621041365_52.zip
// 测试脚本
// $file_path = '../../uploads/八杯水.jpg';
// download_file($file_path);
//type换成这样试下
Header ( "Content-type: application/octet-stream" );