我正在尝试创建一个问题系统,允许用户创建动态数量的问题以及动态数量的答案(他们可以从基于简单文本的答案到基于图像的答案中进行选择)。在请求中包含以下图像文件集合:
'image_opt' =>array:4 [▼
0 => array:1 [▼
0 => "file_q1_1"
1 => "file_q1_2"
]
1 => array:1 [▼
0 => "file_q2_1"
1 => "file_q2_2"
]
2 => array:4 [▼
0 => "file_q3_1"
1 => "file_q3_2"
2 => "file_q3_3"
3 => "file_q3_4"
]
]
如何获取每个文件并将其存储在服务器中?到目前为止,我已经尝试过这个
$answer = new Answer();
$file = $request->image_opt[$i][$j];
$name = str_random(45) . $file->getClientOriginalExtension();
$folder = '/uploads/answers/';
$path = $file->storeAs($folder, $name, 'public');
$answer->answer = $folder . $name;
$answer->question_id = $question->id;
$answer->max_weight = 0;
$answer->weight = $request->image_weight[$i][$j];
$answer->answer_type_id = $question->question_type_id;
$answer->save();
问题是......我无法获取文件,根据错误,我当时只有字符串。
Call to a member function storeAs() on string
也试过哪个也没用。
$file = $request->file(image_opt[$i][$j]);
如何从集合中获取每个文件?$i 代表正在存储的当前问题,$j 代表正在存储的答案,img_opt 是文件的集合。
素胚勾勒不出你