How to upload file in Laravel

Here is example for upload file in larave :

public function user()

{

$user = new User;
$form_input = Input::all();
if (Input::hasFile(‘Picture’)) {  // checking is name of file is picture , you can check whatevr u set
$file = Input::file(‘Picture’);
} else {
$file = ”;
}
if ($file != ”) {
$image_name = $file->getClientOriginalName();

// return your file, suppose u have abc.png, so here filename will be abc.
$img_path = public_path(‘uploads/users/’); // Set your path where you want to upload
$extension = Input::file(‘Picture’)->getClientOriginalExtension(); // getting image extension, example, your file is abc.png, so extension will be .png
$fileName = time() . ‘.’ . $extension; // set new file name
$uploaded_at = $file->move($img_path, $fileName); // this method is use to upload file
} else {
$fileName = ”;
}

$user->Picture = $fileName; // this is your column name in your table
$user->save();

}

Add Comment

Required fields are marked *. Your email address will not be published.