Php $request->;文件不断返回tmp路径

Php $request->;文件不断返回tmp路径,php,laravel,vue.js,Php,Laravel,Vue.js,我正在尝试使用laravel和vue上传一个文件。当我在文件中输入console.log()时,我得到下面的图片,但在控制器中,我只接收到一个tmp路径 Vue onFileChange(e) { ths.file = e.target.files[0]; console.log(this.file) }, submit(){ let form= new FormData() form.append('file', this.file) axios.post('/

我正在尝试使用laravel和vue上传一个文件。当我在文件中输入console.log()时,我得到下面的图片,但在控制器中,我只接收到一个tmp路径

Vue

onFileChange(e) {
   ths.file = e.target.files[0];
   console.log(this.file)
},
submit(){
   let form= new FormData()
   form.append('file', this.file)
   axios.post('/api/archieve',form).then(res=>{
            //
   })
},
控制器

return $request->file //returns "C:\xampp\tmp\php5E67.tmp"
更新 我已经使用dd($request->file('file'))进行了检查;它返回下图,但realPath是错误的。图像存储在我电脑上的另一个文件夹中

请尝试添加标题

  onFileChange(e) {
    this.file = e.target.files[0];
    console.log(this.file)
  },
  submit() {
    let form= new FormData()
    form.append('file', this.file)
    axios.post('/api/archieve', form,  {
      headers: { 'Content-Type': 'multipart/form-data' }
    }).then(res=>{
      //
    })
  },
在控制器中,检查

$request->file('file');
存储文件

use Illuminate\Support\Facades\Storage;
....

$file = $request->file('file');

$path = 'my-uploads'; // path or folder where to save it
$storePath = Storage::put($path, $file);
$fileName = basename($storePath);  // generated file name

$filePath = $path . '/' . $fileName; // path of file in your storage

检查
$request->file()
如果您的表单中有
content type=“multipart/form data”
,请删除它,因为这个答案是说它导致了他的问题@V-K返回空文件。@zizoujab否我没有导致FormData()已包含在default@V-K抱歉,它返回相同的内容C:\xampp\tmp\php8F5A.tmp请输入相同的内容。仅获取tmp路径,它将返回路径。尝试
dd($request->file('file')并签入控制台网络就是这样!现在您可以存储文件
$storePath=Storage::put($pathInStorage,$file)但是为什么realPath是错误的,图像在另一个文件夹中