为什么每个人都想用OriginalClientName上载多个文件,并用“ document” 列将其保存到数据库中,但是当数据保存到数据库中时,上载时文件的名称不相同,我是一个名为“ cv bimo.docx”的上传文件,但在数据库中,名称如下:
C:\Users\bimo_an\AppData\Local\Temp\phpAAF.tmp
我已经在使用方法 getClientOriginalName(),
这是我的功能控制器代码:
..............................
$uploadFile = $request->file('document');
foreach($uploadFile as $file){
$filename = $file->getClientOriginalName();
$folder[] = $file->storeAs('uploads', $filename);
}
$data = [
'mto_number'=>$request->txtDocNumber,
'item_code'=>$request->txtItemCode[$key],
'required_qty'=>$request->txtRequiredQty[$key],
'spare_qty'=>$request->txtSpareQty[$key],
// 'file' => $path[$key]
'category' => $request->category[$key],
'document' => $file
];
ModelMTOItem::insert($data);
答案 0 :(得分:0)
您正在传递文件Path而不是clientOriginalName
$uploadFile = $request->file('document');
foreach($uploadFile as $file) {
$filename = $file->getClientOriginalName();
$data = [
'mto_number'=>$request->txtDocNumber,
'item_code'=>$request->txtItemCode[$key],
'required_qty'=>$request->txtRequiredQty[$key],
'spare_qty'=>$request->txtSpareQty[$key],
// 'file' => $path[$key]
'category' => $request->category[$key],
'document' => $filename
];
ModelMTOItem::insert($data);
$folder[] = $file->storeAs('uploads', $filename);
}