编程语言
首页 > 编程语言> > php-Laravel 5.2中的文件上传错误

php-Laravel 5.2中的文件上传错误

作者:互联网

这是我的upload.blade.php代码

{!!Form::open(array('url'=>'parser','method'=>'POST','enctype'=>'multipart/form-data','onsubmit'=>'return validate(this)', 'files'=>true)) !!}
                <div class="panel panel-default file-upload">
                  <div class="panel-heading">
                    <label for="exampleInputFile">Upload Manually :</label>
                     </div>
                  <div class="panel-body">
                    {!! Form::file('Filename') !!}
             <progress id="progressBar" value="0" max="100" width="100%">
          </progress>
    <h3 id="status"></h3>
    <p id="loaded_n_total"></p>
    {!! Form::submit('Submit', array('class'=>'btn btn-info','value'=>'Upload File')) !!}
          {!! Form::close() !!}

然后我有一个控制器类来移动上传的文件,上传功能是

public function uploadFile(){

     $a=session('upload');
      $path="/logparser/html/upload/".$a;
            $fileExistsFlag = 0;
     $file = array('Filename' => Request::file('Filename'));
             if(!(is_dir($path))){
              mkdir($path, 0777);
              chmod($path,0777); 
              }

             Request::file('Filename')->move($path);

             Session::flash('success', 'Upload successfully');
             return view('dash');
  }

它给出了一个错误:在null上调用成员函数move()
我查看了文件的内容,但数组为空.

解决方法:

我使用此功能上传图片,并且效果很好-

 public function upload_image(){

    $input = Input::instance();
    $destinationPath = public_path("uploads/user");

   if($input->file('user_image')){

    try{
        if ($input->file('user_image')->isValid())
        {
             $extension = $input->file('user_image')->getClientOriginalExtension();
             $fileName = rand(11111, 99999) . '.' . $extension;
             if($input->file('user_image')->move($destinationPath, $fileName)){
            // Updating user image in db

            }else{
                $this->data['message'] = Lang::get('messages.image_upload_fail');
                 $this->utilObj->renderJson('error', $this->data);
            }
        }else{
            $this->data['message'] = Lang::get('messages.image_upload_fail');
            $this->utilObj->renderJson('error', $this->data);
        }
    }
    catch (\Exception $e) {

        Log::error("AppUsers::upload_image()  " . $e->getMessage());
        $this->data['message'] = Lang::get('messages.image_upload_fail');
        $this->utilObj->renderJson('error', $this->data);
        return false;
    }
   }else{

        $this->data['message'] =  Lang::get('messages.image_required');
        $this->utilObj->renderJson('error', $this->data);
        return false;
   }

}

标签:laravel,laravel-5-2,php
来源: https://codeday.me/bug/20191118/2030616.html