4

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.

1
  • Is dd($request::file('Filename'); also empty? Commented Apr 22, 2016 at 9:46

4 Answers 4

3

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".

Sign up to request clarification or add additional context in comments.

Comments

3

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

}

2 Comments

Again it is coming null.... somehow the values are not coming to the controller function.
1

This should work

$file=Input::file('Filename')->getClientOriginalName();
Input::file('Filename')->move($destination,$file);

3 Comments

Error :Call to a member function getClientOriginalName() on null
Maybe you have problem with your javascript function onsubmit, or your validation does not allow file to pass to controller. Try without onsubmit function.
Try adding: uploadFile(Request $request){ dd ($request->file('Filename')); or even dd($request->input()); If thats not working, you are having problem in ur script or form
0

You can write code like this

public function uploadFile(Illuminate\Http\Request $request){
      $a=session('upload');
      $path="/logparser/html/upload/".$a;
      $fileExistsFlag = 0;

      if(!(is_dir($path))){
        mkdir($path, 0777);
        chmod($path,0777); 
      }

      $request->file('Filename')->move($path);
      Session::flash('success', 'Upload successfully');
     return view('dash');
}

For more information you can read document of laravel 5.2 https://laravel.com/docs/5.2/requests#files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.