账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    thinkphp文件下载,下载下的文件损坏
    22
    0
    public function download(){
            $filepath='./uploads/1ce97664a4523e99cc623ad39d98c5b8.jpg';
            if(!file_exists($filepath)){
                $filepath=iconv('utf-8','gb2312',$filepath);
                if(!file_exists($filepath)){
                    exit('文件路径错误');
                }
            }
            $file_size=filesize($filepath);
            header('content-type:application/octet-stream');
            header('accept-ranges:bytes');
            header('accept-length:'.filesize($filepath));
            header('content-disposition:attachment;filename=1ce97664a4523e99cc623ad39d98c5b8.jpg');
            $handle=fopen($filepath,'r');
            $buffer=1024;
            $tot=0;
            while(!feof($handle)&&$tot<$file_size){
                $file_content=fread($handle,$buffer);
                $tot+=$buffer;
                echo $file_content;
            }
            fclose($handle);
        }

    这段代码,我要不放在thinkphp里用,下载下来的文件可以打开。
    但放在thinkphp里用,下载下来的文件就打不开,什么损坏之类的。
    求大神解答

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 乄風飛シ 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部