调用非对象的成员函数获取错误

时间:2016-02-29 14:22:35

标签: php laravel

我尝试了很多次,但这段代码无效。我不知道为什么。这是一个图片上传表单。此代码适用于其他表单但在此处收到错误:Call to a member function isValid() on a non-object

$file = array('dest_img' => Input::file('dest_img'));
// checking file is valid.
    if (Input::file('dest_img')->isValid()) {
        $destinationPath = 'uploads'; // upload path
        $extension = Input::file('dest_img')->getClientOriginalExtension(); // getting image extension
        $fileName = $s.'.'.$extension; 
        $imgPath= $destinationPath.'/'.$fileName;
        //return $imgPath;
        // renameing image
        Input::file('dest_img')->move($destinationPath, $fileName); // uploading file to given path
        // sending back with message
        //Session::flash('success', 'Upload successfully'); 
        //return Redirect::to('tblaze_admin/bannerAdd');

         $data=array(
                    'dest_title'  =>$input['dest_title'],
                    'dest_desc'  =>$input['dest_desc'],
                    'dest_img' =>$imgPath,
            );
            //$result=Cms::where('cms_id',$cms_id)->update($data);

        $result=Destination::where('dest_id',$dest_id)->update($data);
        if($result >0)
        {
            \Session::flash('flash_message','Destination Updated Successfull!!');
        }
         else
         {
          \Session::flash('flash_error_message','Destination Updation Failed!!');
         }  
}

我坚持这个代码;请给出一个解决方案

2 个答案:

答案 0 :(得分:1)

您是否已将enctype="multipart/form-data"添加到<form>代码中?或者,如果您使用的是Form构建器,'files' => true

答案 1 :(得分:0)

Input::file('dest_img')不是对象。您可能尚未加载定义Input的类。检查laravel是否正确引导。