回答

收藏

CMS后台上传的文件如何下载

后台知识 后台知识 350 人阅读 | 0 人回复 | 2024-06-28


1.前端下载
<a href="{dr_get_file(dr_site_value('frjbqkb'))}" download="{dr_get_file(dr_site_value('frjbqkb'))}" style="font-size: 14px;">法人单位基本情况表</a>
注意href一定要填,不然下载的是当前网页内容,会产生文件损坏报错
2.后端下载
前端链接到后端对应的方法:
public function download($path="./data/import.xlsx"){
    if (file_exists($path)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . basename($path) . '"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($path));
        readfile($path);
        exit;
    }
}
分享到:
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

65 积分
15 主题
+ 关注