smartrahat smartrahat - 1 year ago 87
PHP Question

Laravel 5 can't store image name in database

I am using Laravel 5.1

I can move image to my destination folder with correct name but in database it's saved with a temp name, like



<div class="form-group">
{!! Form::label('image', 'Upload Image', ['class'=>'control-label col-sm-4']) !!}
<div class="col-sm-8">
{!! Form::file('image', null) !!}


public function store(TeacherRequest $request)
$image_name = $request->file('image')->getClientOriginalName();
$request->file('image')->move(base_path().'/public/images', $image_name);
Session::flash('success_message', 'Teacher has been added successfully!');
return redirect('teacher');

Answer Source

I am having the same problem when updating the record with new image,image name save in correct name but tmp name in database like 'C:\wamp\tmp\phpD10D.tmp' what i did before saving is

$request['img'] = $imageName; //with new name

I know it should be like $_FILE['img']['name'] = $imageName

but how to manage it in Laravel 5.1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download