我有一个表单,用户可以在其中将文件上传到上传文件夹。在 Controller 中,我需要检查文件是否已存在于上传目录中,如果存在则不允许将同一文件上传两次。 我该如何检查?
最佳答案
也许问题在于您正在检查文件是否存在于服务器的根文件夹中。
试试这个
if (file_exists(public_path('uploads/'.$file->getClientOriginalName()))) {
return redirect()->back()->withInput()->withErrors([' File already exists.']);
}
https://stackoverflow.com/questions/31973490/