问题描述:

i am new in laravel, i am facing a big problem and i can't solve this problem.

I am trying to upload image into my database and upload folder,but my code is not working,

Here is my controller code

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

}

please help me as soon.

Thank you.

相关阅读:
Top