gpt4 book ai didi

php - 拉维尔 : $request->hasFile() is not working

转载 作者:可可西里 更新时间:2023-10-31 22:54:18 28 4
gpt4 key购买 nike

我有一个表格,可以得到 title , description和一个 image .当我 dd($requests->all()); , 它返回以下正确的。

array:4 [
"projectTitle" => "asd"
"project_description" => "asd"
"project_image" => "15940723_1336567063030425_9215184436331587115_n.jpg"
"_token" => "eUj27iioySvIgut5Afu0ZHMgeVrO99a9e1o7Tw0w"
]

我将这些值存储为:

$project = new Portfolio;
$project->freelancer_id = Auth::user()->id;
$project->title = $request->get('projectTitle');
$project->description = $request->get('project_description');

if($request->hasFile('project_image')){
$project_image = $request->file('project_image');
$filename = time() . '.' . $project_image->getClientOriginalExtension();
Image::make($project_image)->resize(197, 137)->save( public_path('/uploads/portfolios/' . $filename ) );
$project->img = $filename;
}

$project->save();

但是 img数据库表字段为空。

if($request->hasFile('project_image'))没有得到领域,

我还有表格,方法是 POST并且有 enctype="multipart/form-data"和一个文件我有 <input type="file" name="project_image" id="project_image"> .

我做错了什么?

最佳答案

如果您的代码中的一切都会正确,那么您可能会遗漏enctype,我在启动时也遗漏了它,

<form action="{{ route('store') }}" method="POST" enctype="multipart/form-data">

或者,如果您使用 Form Helper,该 enctype 很容易包含在 file=true 字段中。

{!! Form::open(['route' => ['store'], 'file' => true]) !!}

关于php - 拉维尔 : $request->hasFile() is not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41697980/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com