thinkphp上传下载文件

  • 上传
<input type="file" name="file" ref="file"/>
    <span @click="upload">提交</span>
    upload(){
        let form = new FormData();
        form.append("file", this.$refs.file.files[0]);
        let config = {
          headers: { "Content-Type": "multipart/form-data" }
        }
        axios.post(‘http://localhost/tp5/public/index/index/upload', form, config).then(
           (res)=> {
             console.log('上传成功')
           })
          .catch( (err) =>{
          });
      }
use think\Request;
public function upload(Request $request){
        $file = $request->file('file');
        $res = $file->move(ROOT_PATH.'public');
        echo $res;
    }

在这里插入图片描述

  • 下载
<a href="http://localhost/tp5/public/20200229/3bf402917a41e3e64a693e84d7c527bc.docx" download>下载</a>
发布了122 篇原创文章 · 获赞 5 · 访问量 4827

猜你喜欢

转载自blog.csdn.net/weixin_41254345/article/details/104567257