I am using laravel 5 to create an edit form for a profile and can update picture in the form.
I want to store a new image in edit form. I use this code in edit.blade to get the image by user.
View:
{!! Form::model($dataItemregistration,['method' => 'PATCH', 'action' => ['Modul\ProfilController@update', $dataItemregistration->ItemRegistrationID, 'files' => true] ]) !!}
<div class="form-group">
<div class="row">
<div class="col-lg-3">
{{ Form::label('pic', 'Gambar (Saiz gambar, 250x300px)') }}
</div>
<div class="col-lg-7">
{!! Form::file('gambar', array('class' => 'form-control')) !!}
</div>
</div>
</div>
<br>
<div class="col-lg-10 text-center">
{!! link_to(URL::previous(),'Back', ['class' => 'btn btn-warning btn-md']) !!}
{{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
</div>
{!! Form::close() !!}
Controller:
public function update(Request $request, $id)
{
$valueitemregistrations = Itemregistration::find($id);
$this->validate($request,['gambar' => 'max:100000',]);
if ($request->hasFile('gambar')) {
// Get the file from the request
$file = $request->file('gambar');
// Get the contents of the file
$content = $file->openFile()->fread($file->getSize());
$valueitemregistrations->Picture = $content;
$valueitemregistrations->update();
if($valueitemregistrations) {
return redirect('profil');
} else {
return redirect()->back()->withInput();
}
} else {
echo "testing";
}
}
When I try to upload and update, it goes to echo "testing". It doesn't detected any files uploaded..
I had been using the same code for add.blade and it works.
Is it related to route path or else?
Try changing the permissions on the wp-content directory to 766. If you still have problems, try 767, 775 or 777. Once your uploads are working, change the permissions on wp-content back to 755 again and check that everything still works OK.
Just check if it starts with image/ . String fileName = uploadedFile. getFileName(); String mimeType = getServletContext(). getMimeType(fileName); if (mimeType.
This happens when your HTML form doesn't have enctype="multipart/form-data"
.
In this case the cause is 'files' => true
being part of the wrong array inside Form::model()
; it's inside the 'action'
array when it should be outside. Try this:
Form::model($dataItemregistration, [
'method' => 'PATCH',
'action' => ['Modul\ProfilController@update', $dataItemregistration->ItemRegistrationID],
'files' => true,
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With