我有一个表单,在表单内我可以输入多个图像,并将其转换为 json
我的表单 html create.blade.php
<form method="post" action="{{ route('m_announcement.store') }}" enctype="multipart/form-data">
@csrf
/////// many input just not included
//////// my image input
<div class="row mb-4">
<label class="col-sm-2 col-label-form">Upload Images</label>
<div class="col-sm-10">
<input type="file" name="files[]" id="files" multiple
accept="image/jpeg, image/png, image/gif," onchange="timeFunction()"><br />
</div>
</div>
///////// my imagae preview
<output id="Filelist"></output>
<div class="text-center">
<input type="submit" class="btn btn-primary" value="Add" />
</div>
</form>
脚本中的此函数以 json 格式将图像输出到 var AttachmentArray,我也想通过表单发布
function printvalues() {
console.log(AttachmentArray); all image converted in base64 output in json format with imahe details
有没有办法将 json 连接到表单,当我按提交 json 时,数据将根据请求输出
laravel 9 公告控制器.php
public function store(Request $request)
{
//dd($request);
$jsonimages = $request->jsonimages;
// decode the json a create loop to upload to database image
// some code to upload the form to announcement database
//image upload
}
我不只是在前端,大多数时候我首先在后端开发,这是我的第一个网络应用程序项目,我尝试搜索ajax或其他东西,但我还不明白。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您可以使用以下方式获取字段输入的名称
dd($request->file->('files'));请参阅此处了解更多信息在 laravel 9 中检索上传的文件一个>