i am stuck with image uploading in laravel 5.6. text input is fine but image not uploading.
for testing route and input field, i put a demo echo for retrive text field data and it show perfectly. but image is not uploading... but i used same code in my previous project to image uploading and that was good..this time is not working.
controller-
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
class UserController extends Controller
{
public function insertChildren(Request $request){
echo $request->input('firstName');
//this echo doing well
if ($request->hasFile('image')) {
$imageExtention=$request->file('image')->getClientOriginalExtension();
$randomString=substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 10)), 0, 10);
$modifiedImageName=$randomString.'.'.$imageExtention;
$productImage->move(public_path('img'),$modifiedImageName);
}
}
}
Form
<form role="form" action="" method="post">
@csrf
<div class="form-group ml-4 mr-4">
<div class="row">
<div class="col-6">
<label for="name">First Name</label>
<input value="" name="firstName" type="text" class="form-control" id="first" placeholder="First Name">
</div>
<div class="col-6">
<label for="name">Last Name</label>
<input value="" name="lastName" type="text" class="form-control" id="last" placeholder="Last Name">
</div>
</div>
</div>
<div class="form-group ml-4 mr-4">
<label for="gender">gender</label>
<br>
<input value="" type="text" name="gender" class="form-control" placeholder="Boy or Girl or Other">
</div>
<div class="form-group ml-4 mr-4">
<label for="Birthday">Birthday</label>
<input name="birthday" type="date" class="form-control" id="birthday">
</div>
<div class="form-group ml-4 mr-4">
<label for="image">Profile Image</label>
<input type="file" name="image" class="form-control" id="image">
</div>
<button type="submit" style="background-color:#2DAE60;" class="btn">
<i class="fa fa-plus"></i> ADD </button>
</form>
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire