在字符串上调用成员函数move()

时间:2017-06-20 07:59:26

标签: php laravel file file-upload image-uploading

请帮我处理以下代码。当我尝试上传多张图片时,我不断收到此错误“调用成员函数move()”。提前感谢。

这是我的视图页面的代码

  {!!Form::open(['method'=>'POST','action'=>'ClientController@uploadLand','files'=>true])!!}
         {{ csrf_field() }}

          <div class="admin-form">

            <div class="row">
              <div id="maindiv">
                  <div id="formdiv">
                      <div id="filediv"><input name="file[]" type="file" id="file"/></div><br/>
                      <input type="button" id="add_more" class="upload" value="Add More Files"/>
                     <!--  <input type="submit" value="Upload File" name="submit" id="upload" class="upload"/> -->
                      <br/>
                      <br/>
                  </div>
              </div>
            </div>
  {!!Form::close()!!}

这是控制器代码

public function uploadLand(Request $request)
{
    for($i=0;$i<count($_FILES["file"]["name"]);$i++){

    $image= "";
    $file_path="images/uploads";
    $imageName = $_FILES['file']['name'][$i];
    $image->move(public_path($file_path),$imageName);
    //$image->move_uploaded_file("images/uploads".$imageName);

    }
 }

1 个答案:

答案 0 :(得分:0)

尝试以下代码:

if ($request->hasFile('file')) {
    $destinationPath = 'path/th/save/file/';
    $files = $request->file('file'); // will get all files

    foreach ($files as $file) {//this statement will loop through all files.
        $file_name = $file->getClientOriginalName(); //Get file original name
        $file->move($destinationPath , $file_name); // move files to destination folder
    }
}