【发布时间】:2021-10-06 12:27:53
【问题描述】:
我有一个 Laravel 控制器函数 file_fetch()
public function file_fetch(Request $request) {
$file = request('routename');
$destinationPath = public_path('/folder/'.$file);
if(!File::exists($destinationPath)){
$content = File::get($destinationPath);
return view('filefetch', compact('file','content'));
}
else {
return redirect('/')->witherrormessage('NO such File Exists');
}
}
如果我检查文件public/folder/app/index.html 并且如果我检查public/newfolder(新文件夹不存在)并且因此它执行else 函数并重定向错误消息,则此方法有效,但如果我搜索public/folder/app/ 我没有指定了文件名,但目录存在,因此 if(!File::exists($destinationPath)) 函数正在执行!
我想检查目录中的文件,即使目录存在,如果文件不存在,则抛出错误消息,说文件不存在。
【问题讨论】: