返回文件的上传和下......登陆

文件的上传和下载

cherry2019-02-21 14:43:11277

//文件的下载

function dowFile($fileName){
//    header( "Content-Disposition:  attachment;  filename=".$fileName); //告诉浏览器通过附件形式来处理文件
//    header('Content-Length: ' . filesize($fileName)); //下载文件大小
//    readfile($fileName);  //读取文件内容
    header('Accept-length:'.filesize($fileName));
    header( "Content-Disposition:  attachment;  filename=".basename($fileName));
    readdFile($fileName);
}

//文件的上传

function upLodFile($fileInfo,$fulePath = './upload',$maxSize = 1000000,$allowExt = ['png','jpg','jpeg','txt']){
    if($fileInfo['error'] === 0){
        $ext = strtolower(pathinfo($fileInfo['name'],PATHINFO_EXTENSION));
        if(!in_array($ext,$allowExt)){
            return '文件格式不正确';
        }
        if($fileInfo['size']>$maxSize){
            return '文件太大'.$fileInfo['size'];
        }
        //判断文件上传方式
        if(!is_uploaded_file($fileInfo['tmp_name'])){
            return '文件非法上传';
        }
        if(!file_exists($fulePath)){
           mkdir($fulePath,0777,true);
        }
        //md5生成唯一文件名 uniqid唯一当前时间戳微秒值
        $path = md5(uniqid(microtime(true),true)).'.'.$ext;
        $dest = $fulePath.'/'.$path;
        if(!move_uploaded_file($fileInfo['tmp_name'],$dest)){
            return '文件上传失败';
        }
        return '文件上传成功';
    }else{
        return '失败error = '.$fileInfo['error'];
    }

}


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送