muragijimana's avatar

trouble uploading image to a folder

here is my code:

            $destinationPath = 'images/uploads'; // upload path
            $top_extension = Input::get('top_banner')->getClientOriginalExtension(); 
            $bottom_extension = Input::get('bottom_banner')->getClientOriginalExtension(); 

            $fileName_top = rand(11111,99999).'.'.$top_extension; // renameing image
            $fileName_bottom = rand(11111,99999).'.'.$bottom_extension; // renameing image

            Input::file('top_banner')->move($destinationPath, $fileName_top);//moving topBanner into folder
            Input::file('bottom_banner')->move($destinationPath, $fileName_bottom);//moving topBanner into folder

            $insert_banner_top=DB::table('events')->where('id',$k)->update('top_banner', Input::get('top_banner'));
            $insert_banner_bottom=DB::table('events')->where('id',$k)->update('bottom_banner', Input::get('bottom_banner'));

            echo "uploaded"; exit();

and i am getting this error: Call to a member function getClientOriginalExtension() on a non-object

0 likes
2 replies
FatihKececi's avatar

Change this lines

$destinationPath = 'images/uploads'; // upload path
$top_extension = Input::get('top_banner')->getClientOriginalExtension(); 
$bottom_extension = Input::get('bottom_banner')->getClientOriginalExtension(); 

instead of

$top_banner = Input::file('top_banner'); // you can check with Input::has() or dd() / var_dump()
$bottom_banner = Input::file('bottom_banner'); // you can check with Input::has() or dd() / var_dump()
$destinationPath = public_path() . 'images/uploads'; // or base_path() if you don't use public folder
$top_extension = $top_banner->getClientOriginalExtension();
$bottom_extension = $bottom_banner->getClientOriginalExtension(); 

i hope you helpful.

Please or to participate in this conversation.