//文件的下载
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']; } }