programing

Laravel Storage 폴더에 대한 경로는 어떻게 얻습니까?

goodjava 2022. 10. 21. 21:23

Laravel Storage 폴더에 대한 경로는 어떻게 얻습니까?

업로드한 이미지를 Laravel 기반의 웹 앱에 Laravel의 서브디렉토리에 저장하고 싶다.storage디렉토리로 이동합니다.이것은 '애플리케이션' 및 '퍼블릭' 디렉토리와 동일한 계층 수준의 디렉토리입니다.

이를 위한 프레임워크 방법이 있습니까?서류를 찾아봤지만 찾을 수가 없어요.

Larabel 5.x의 경우$storage_path = storage_path().

Larabel 5.0 문서:

storage_path

에 대한 완전 수식 경로를 가져옵니다.storage디렉토리로 이동합니다.

또, Larabel 5.1 이후의 경우는, Larabel 5.1 문서 마다 다음의 순서에 주의해 주세요.

를 사용할 수도 있습니다.storage_path스토리지 디렉토리를 기준으로 지정된 파일에 대한 완전 수식 경로를 생성하는 함수:

$path = storage_path('app/file.txt');

Larabel 3에서 를 호출합니다.

Larabel 4에서는 도우미 기능을 사용합니다.

Larabel 버전 > = 5.1의 경우

storage_path()

storage_path함수는 스토리지 디렉토리의 완전 수식 경로를 반환합니다.

$path = storage_path();

를 사용할 수도 있습니다.storage_path스토리지 디렉토리를 기준으로 지정된 파일에 대한 완전 수식 경로를 생성하는 함수:

$app_path = storage_path('app');
$file_path = storage_path('app/file.txt');

출처: 라라벨 문서

이 장인 명령을 사용하여 공용 폴더에 바로 가기 만들기

php artisan storage:link

게시된 img 또는 파일에 액세스할 수 있습니다.

Larabel 8.x <

파일이 기본 Disk에 있는 경우: /storage/app/public/file.jpg:

$path = Storage::path('file.jpg');

파일이 다른 저장소에 있는 경우.예: /storage/app/storage-dir/sub-dir/file.txt

Storage::disk('storage-dir')->path('sub-dir/file.txt')

$path는 "/var/www/project1/storage/app/storage-dir/sub-dir/file.txt"가 됩니다.

또 있다url()

$path = Storage::disk('storage-dir')->url('sub-dir/file.txt');

그러면 다음과 같은 경로가 반환됩니다./storage/sub-dir/file.txt

ealier Larabel 버전의 경우:storage_path('app/file.txt');

를 사용할 수 있습니다.storage_path();스토리지 폴더 경로를 가져오는 함수입니다.

storage_path(); // Return path like: laravel_app\storage

로그 파일을 저장한다고 가정합니다.mylog.log저장소 폴더의 로그 폴더 안에 있습니다.이렇게 써야 돼요.

storage_path() . '/LogFolder/mylog.log'

언급URL : https://stackoverflow.com/questions/16597392/how-do-you-get-the-path-to-the-laravel-storage-folder