你好,我在拉拉维新手,所以我真的需要一些帮助。我想创建一个代码,其中只有图片可以上传其他文件不能,我试图使用代码输入文件,但是当我尝试上传zip文件时,它仍然上传,所以我真的需要帮助php - 如何使文件上传唯一图像 - Laravel
This是我的表码
<div class="col-sm-5">
{!! Form::label('photo', 'Photo:') !!}
<input type='file' name='photo' class='form-control' accept = 'image/jpeg , image/jpg, image/gif, image/png'>
这是我的控制器
public function store(CreateBannerRequest $request)
{
$input = $request->all();
//get original file name
if($request->photo == NULL)
{
Flash::error('Image must be filled');
return back();
}
$filename = Input::file('photo')->getClientOriginalName();
$input['photo'] = $filename;
$banner = $this->BannerRepository->create($input);
//upload file
Input::file('photo')->move($this->path, $filename);
Flash::success('Banner saved successfully.');
if (empty($banner)) {
Flash::error('No image available');
return redirect(route('banner.index'));
}
return redirect(route('banner.index'));
}
嗨,你在那里,你需要在后端验证文件类型,只需要在前端名称的文件上传字段。 –
@SagarGautam你能告诉我的代码请:D –
我会添加回答 –