Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file upload error in laravel 5.2

This is my upload.blade.php code

{!!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() !!}

Then i am having a controller class to move uploaded file, the upload function is

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');
  }

It is giving an error: Call to a member function move() on null And i looked at the contents of file but the array was empty.

like image 948
Aman Malviya Avatar asked Mar 12 '23 12:03

Aman Malviya


2 Answers

Solved the problem just by making changes into the php.ini file. I have changed the "upload_max_filesize=-1" and "post_max_size=-1".

like image 78
Aman Malviya Avatar answered Mar 16 '23 07:03

Aman Malviya


I use this function for uploading image and it is working fine -

 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;
   }

}
like image 45
Afshan Shujat Avatar answered Mar 16 '23 05:03

Afshan Shujat