图片上传代码无效

时间:2015-02-11 18:53:03

标签: laravel-4

我是laravel的新手,我面临一个大问题,我无法解决这个问题。 我正在尝试将图像上传到我的数据库和上传文件夹,但我的代码无效, 这是我的控制器代码

public function store()
    {
        $rules=array(
              'gallery_name'=>'required',
              'image_title'=>'required',
              'image'=>'required'
        );
        $file = Input::file('image');
        $destinationPath = 'uploads/';
        // If the uploads fail due to file system, you can try doing public_path().'/uploads' 
        $filename = str_random(32) . '.' . $file->getClientOriginalExtension();
        //$filename = $file->getClientOriginalName();
        //$extension =$file->getClientOriginalExtension(); 
        //get all book information
        $galleryInfo = Input::all();
        //validate book information with the rules
          $validation=Validator::make($galleryInfo,$rules);
          $upload_success = Input::file('image')->move($destinationPath, $filename);
          if($validation->passes())
          {
          //save new book information in the database 
          //and redirect to index page
              if ($upload_success) {
                    //save in the Band table database
                    Gallery::create($galleryInfo);
                            return Redirect::route('galleries.index')
                             ->withInput()
                             ->withErrors($validation)
                             ->with('message', 'Successfully created Gallery.');
                    }   
                     else {
                           return Redirect::route('galleries.create')
                           ->withInput()
                           ->withErrors($validation)
                           ->with('message', 'Image fields are incomplete.');
                    }
          }
          //show error message
          return Redirect::route('galleries.create')
               ->withInput()
               ->withErrors($validation)
               ->with('message', 'Some fields are incomplete.');
     } 

请尽快帮助我。 谢谢。

0 个答案:

没有答案