Laravel 5.4 Multiple Upload TMP notfoundexception

时间:2018-10-18 05:55:35

标签: laravel-5 php-5.6

这是我在laravel 5.4和php 5.6中的第一个项目,我希望使用来自以下库中的move()的多个输入来使用多上传图像。但是它仅从第一个输入上传文件,并给我错误

  

FileNotFoundException,文件“ ... tmp”不存在。 MimeTypeGuesser.php第116行

这是我从控制器上传的代码

 if($request->hasFile('foto'))
    {
        $number = 1;
        foreach ($request->file('foto') as $file) {
            $file->move('images/'.$id,'foto'.$number. '.' . $file->extension());
            $number++;
        }
    }

这是我查看的表单

  <form action='{{url("profile/edit")}}' method="post" enctype="multipart/form-data">
            {{csrf_field()}}
                  <span>Foto</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto2</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto3</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto4</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto5</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto6</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto7</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="file-field input-field col s6">
                <div class="btn teal darken-1">
                  <span>Foto8</span>
                  <input name="foto[]" type="file">
                </div>
                <div class="file-path-wrapper">
                  <input class="file-path validate" type="text" placeholder="Pilih pas foto">
                </div>
              </div>
              <div class="col s12">
                @if (count($errors) > 0)
                  @foreach ($errors->all() as $error)
                    <p>{{ $error }}</p>
                  @endforeach
                @endif
              </div>
              <div class="input-field col s12 center">
                <input type="submit" value="Submit" class="waves-effect waves-light btn cyan">
              </div>
            </form>

,当使用dd($ request-> foto)时,将给出一个包含所有图像的数组。你们能告诉我我的错误在哪里吗?以及我该如何解决这个问题,谢谢!

更新:我做到了!我使用storeAs()而不是之前使用过的move()解决了它。不过,我真的很想知道为什么storeA在移动时没有起作用?谢谢!

0 个答案:

没有答案