I am trying to upload images but unfortunately, I am getting errors when submitting the form please help me how can resolve that?
please check the error https://flareapp.io/share/KPgXYVg7
uploader desgin https://ibb.co/WpxS0Yk
controller
public function store(Request $request)
{
// dd($request->all());
foreach ($request->file('image') as $key => $value) {
$extension = $value->getClientOriginalExtension();
$image[$key] = $value->getFilename() . '.' . $extension;
Storage::disk('yourstitchart')->put($value->getFilename() . '.' . $extension, File::get($value));
}
$input = $request->except("_token");
$input['user_id'] = Auth::user()->id;
$input['image'] = $image;
Digitizingorder::create($input);
return redirect()->back();
}
HTML view
script
$(document).ready(function () {
$("#upload_files").change(function (e) {
// readURL(this);
var jamo = window.URL.createObjectURL(this.files[0]);
$('#upload-preview').attr('src', jamo);
var imgpath = document.getElementById('upload_files');
if (!imgpath.value == "") {
var img = imgpath.files[0].size;
var imgsize = img / 1024;
var imgsizeN = imgsize.toFixed(2);
}
var fileName = e.target.files[0].name;
$('.file_list').append(`
<p class="image_data" src="${jamo}"> ${imgsizeN} kb / ${fileName} </p>
<input type="text" name="image[]" value="${fileName}" >
`);
var file = (e.srcElement || e.target).files[0];
console.log(file);
});
$(document).on('click', '.image_data', function () {
var getSrc = $(this).attr('src');
$('#upload-preview').attr('src', getSrc);
});
});