laravel 请求文件 return 空(已添加 enctype)
laravel request file return null (enctype added)
当我上传任何东西时,它 return 是 null 但如果我尝试在我的控制器中 return $_FILES 它 return 是我上传的文件,我添加了 enctype="multipart/form-data" 但仍然没有运气
这是我的表格
<form action="{{url('add_attachments')}}" method="post" enctype="multipart/form-data">
@csrf @method('put')
<div class="row">
<div class="col-12">
<label class="small">Tambahkan lampiran</label>
<div class="form-group mb-1 upload">
<input type="file" name="lampiran[]" multiple accept="image/jpeg,image/gif,image/png,application/pdf" />
</div>
</div>
</div>
<div class="row">
<div class="col">
<button type="submit">Upload</button>
</div>
</div>
</form>
这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProposalController extends Controller
{
public function add_attachment(Request $request, $id)
{
return $request->file('lampiran'); //return null
return $_FILES; //return {"lampiran":{"name":["7680cf333da548d4213fd5f574b66ffbdccba917.jpg"],"type":["image\/jpeg"],"tmp_name":["\/tmp\/phpBIcJYs"],"error":[0],"size":[138198]}}
}
}
你的<input type="file" name="lampiran[]" multiple accept="image/jpeg,image/gif,image/png,application/pdf"/>
是一个数组lampiran[]
试试这个
public function add_attachment(Request $request,$id)
{
return $request->file('lampiran.0');
}
或
public function add_attachment(Request $request,$id)
{
foreach($request->file('lampiran') as $image){
dd($image):
}
}
当我上传任何东西时,它 return 是 null 但如果我尝试在我的控制器中 return $_FILES 它 return 是我上传的文件,我添加了 enctype="multipart/form-data" 但仍然没有运气
这是我的表格
<form action="{{url('add_attachments')}}" method="post" enctype="multipart/form-data">
@csrf @method('put')
<div class="row">
<div class="col-12">
<label class="small">Tambahkan lampiran</label>
<div class="form-group mb-1 upload">
<input type="file" name="lampiran[]" multiple accept="image/jpeg,image/gif,image/png,application/pdf" />
</div>
</div>
</div>
<div class="row">
<div class="col">
<button type="submit">Upload</button>
</div>
</div>
</form>
这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ProposalController extends Controller
{
public function add_attachment(Request $request, $id)
{
return $request->file('lampiran'); //return null
return $_FILES; //return {"lampiran":{"name":["7680cf333da548d4213fd5f574b66ffbdccba917.jpg"],"type":["image\/jpeg"],"tmp_name":["\/tmp\/phpBIcJYs"],"error":[0],"size":[138198]}}
}
}
你的<input type="file" name="lampiran[]" multiple accept="image/jpeg,image/gif,image/png,application/pdf"/>
是一个数组lampiran[]
试试这个
public function add_attachment(Request $request,$id)
{
return $request->file('lampiran.0');
}
或
public function add_attachment(Request $request,$id)
{
foreach($request->file('lampiran') as $image){
dd($image):
}
}