简体   繁体   中英

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 D:\\xampp\\tmp\\phpC7EA.tmp

form.blade.php

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

TeacherController.php

public function store(TeacherRequest $request)
{
    Teacher::create($request->all());
    $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');
}

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
$images->update($request->all());

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

but how to manage it in Laravel 5.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM