在Laravel 5.8应用程序中提交请求时,我似乎无法让我的应用程序上传文件。无论我上传哪种类型的文件,hasFile()
总是返回false
。
<form action="{{ route('items.store') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group py-50">
<input type="file" name="featured_img" value="featured_img" id="featured_img">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Upload Image" name="submit">
</div>
</form>
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//Check if image has been uploaded
if($request->hasFile('featured_img')){
return "True!";
} else {
return "False!";
}
}
array:7 [▼
"_token" => "sREFSO8bs0rWil05AESVrwEl37XtKOJAF2nCkTNR"
"status" => "published"
"featured_img" => "example.jpg"
"submit" => "Upload Image"
]
enctype="multipart/form-data"
已包含在我的表单中。php.ini
dd($request->all());
返回"featured_img"
的字符串名称,而不是文件对象在更改我的视图时,我没有意识到我有两个采用相同路线的表单操作。愚蠢的我。感谢所有帮助我进行故障排除的人。
答案 0 :(得分:0)
我在其中一项安装中进行了测试 在web.php中
Cell class:
def call(self, inputs, states, training=None):
#cell
reshaped = Reshape([12, 16])(inputs)
state_h = self.summarizeLayer(reshaped)
inputsx = state_h[0]
return super(SummarizeLSTMCellExtended, self).call(inputsx, states, training)
在test.blade.php
use Illuminate\Http\Request;
Route::get('test', function(){
return view('test');
});
Route::post('test', function(Request $request){
dd($request->hasFile('test'));
})->name('test');
<form action="{{ route('test') }}" method="POST" enctype="multipart/form-data">
@csrf
<div class="form-group py-50">
<input type="file" name="test" id="featured_img">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Upload Image" name="submit">
</div>
</form>
返回true,如果有任何问题,请在您的控制器或路由文件中检查此代码,并告诉我。
也
您应该使用@stack将脚本添加到刀片中,而不是@section
更新
根据更新后的视图页面代码,视图中有两个表单发布到同一路线,请检查第一个表单未关闭,第二个表单已打开。
答案 1 :(得分:0)
检查尝试以下情况: