我正在使用Laravel 8.35.1,并尝试检查文件夹是否存在,或者如果不存在,则创建它。路径为:
data/4d61c171-cd94-48ec-82bb-8fee7394471a/processor/333afcbc-37be-4e19-bddc-605c21e766bb
data/4d61c171-cd94-48ec-82bb-8fee7394471a/downloads/333afcbc-37be-4e19-bddc-605c21e766bb
文件夹应在storage/app/
中创建。
我对两条路径都做同样的操作:
$processFolder = $fileHelper->existOrCreate('data/4d61c171-cd94-48ec-82bb-8fee7394471a/processor/333afcbc-37be-4e19-bddc-605c21e766bb');
$downloadFolder = $fileHelper->existOrCreate('data/4d61c171-cd94-48ec-82bb-8fee7394471a/downloads/333afcbc-37be-4e19-bddc-605c21e766bb');
public function existOrCreate($path)
{
if (!File::exists($path)) {
if (!File::makeDirectory($path, 0755, true)) {
send_error_mail('Folder could not be created: ' . $path);
}
}
return $path;
}
问题是,在中总是错误地创建下载文件夹
/public/data/4d61c171-cd94-48ec-82bb-8fee7394471a/downloads/333afcbc-37be-4e19-bddc-605c21e766bb
并且在中正确创建了处理器文件夹
/storage/app/data/4d61c171-cd94-48ec-82bb-8fee7394471a/processor/333afcbc-37be-4e19-bddc-605c21e766bb
有什么想法吗?
使用Storage
立面而不是File
立面。