로컬 파일을 가져오고 파일 이름을 가져오려면 (larvel)
2613 단어 Laravelstorageuploadedfiletech
$file = request()->file("file");
$fileNmae = $file->getClientOriginalName();
나는 로컬 파일에서도 같은 일을 하고 싶다.UploadedFile 클래스를 사용합니다.
요청한 파일 (상기 코드의 예로 변수 $file) 은 UplodFile 클래스의 실례입니다.
나는 로컬 파일
Storage::get(storage_path("app/test.png"))
을 얻기 위해 Storage를 이렇게 사용하지만, Storage는 안 된다.따라서 UploadedFile 클래스를 사용하여 인스턴스를 생성합니다.
$image = new UploadedFile(storage_path("app/test.png", "test.png");
$fileName = $image->getClientOriginalName();
이렇게 하면 요청을 통해 파일을 순조롭게 얻을 수 있는 상황과 같다.※ 경품
예를 들어, 로컬 폴더의 모든 이미지를 가져오려면 Storage를 사용합니다.
이렇게 된 느낌.
$localFiles = Storage::disk("local")->files("/images");
foreach ($localFiles as $file) {
$image = new UploadedFile(storage_path("app/" . $file), $file);
$fileName = $image->getClientOriginalName();
}
의외로 인터넷에는 전혀 정보가 없어 고전했다.
Reference
이 문제에 관하여(로컬 파일을 가져오고 파일 이름을 가져오려면 (larvel)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/naoki_oshiumi/articles/3c628bb0782306텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)