Php 如何使用2个输入文件创建多个上载文件

Php 如何使用2个输入文件创建多个上载文件,php,laravel,laravel-7,Php,Laravel,Laravel 7,我将创建多个上传文件与2个输入文件,但我不知道 Fields.blade.php {!!Form::label('cover','cover:') {!!Form::file('cover',null,['class'=>'Form control']) {!!Form::label('full','full:') {!!Form::file('full',null,['class'=>'Form control']) CatalogController.php 公共函数createWith

我将创建多个上传文件与2个输入文件,但我不知道

Fields.blade.php

{!!Form::label('cover','cover:')
{!!Form::file('cover',null,['class'=>'Form control'])
{!!Form::label('full','full:')
{!!Form::file('full',null,['class'=>'Form control'])
CatalogController.php
公共函数createWithCategory($id)
{
$katalog_metadata=KatalogMetadata::with('metadata')->where('category_id',$id)->get();
返回视图('catalog.create')->带有('katalog_metadata',$katalog_metadata)->带有('category_id',$id);
}
公共函数存储(CreateCatalogRequest$request)
{
$input=$request->all();
if(Auth::user()->can('isAdmin')){
$input['status']=1;
}否则{
$input['status']=0;
}
$input['cover']=$this->uploadingCover($request);
$input['full']=$this->uploadingFull($request);
$catalog=$this->catalogRepository->create($input);
foreach($input['metadata']作为$key=>$value){
$val=[
'metadata_id'=>$key,
'metadata_key'=>$value['key'],
'value'=>$value['value'],
'catalog_id'=>$catalog->id
];
$data=新CatalogMetadataValue($val);
$catalog->catalog\u metadata\u value()->保存($data);
}
如果(!Auth::user()->can('isAdmin')){
$admin=User::where('role_id','1')->first();
邮件::发送($admin->email)->发送(new NotifyNewCatalog($catalog));
}
Flash::success('Catalog saved successfully');
返回重定向(路由('catalogs.index_with_category',$request->category_id));
}
受保护功能上载封面($request)
{
$destinationPath='catalog/cover';
如果(!is_dir($destinationPath)){
如果(!is_dir('catalog')){
mkdir(“目录”);
}
mkdir($destinationPath);
}
如果($request->hasFile('cover')){
$file=$request->file('cover');
$fileName=time().。$file->getClientOriginalExtension();
$file->move($destinationPath,$fileName);
返回$destinationPath.'/.$fileName;
}
返回;
}
受保护函数上载完整($request)
{
$destinationPath='catalog/full';
如果(!is_dir($destinationPath)){
如果(!is_dir('catalog')){
mkdir(“目录”);
}
mkdir($destinationPath);
}
如果($request->hasFile('full')){
$file=$request->file('full');
$fileName=time().。$file->getClientOriginalExtension();
$file->move($destinationPath,$fileName);
返回$destinationPath.'/.$fileName;
}
返回;
}
谢谢

  • 文件元素名称应在数组中,并添加多个关键字
  • 即{!!表单::文件('cover[],null,['class'=>'表单控件','multiple']))
    !!} 
    
  • 在控制器中,使用阵列数据进行上载
  • if($request->hasFile('cover')){
    foreach($request->file('cover')作为$file)
    {
    $fileName=time().。$file->getClientOriginalExtension();
    $file->move($destinationPath,$fileName);
    $data[]=$name;
    }
    }
    
    欢迎来到SO。。。你得到了什么错误。?不要出错,但idk如何创建它。。。