Để lấy danh sách tất cả các tệp từ thư mục chung, bạn có thể sử dụng Mặt tiền tệp. Để làm việc với nó, bạn cần bao gồm lớp sau Show use Illuminate\Support\Facades\File; Các tệp sau có trong thư mục công cộng - ví dụ 1Để lấy tất cả các tệp từ thư mục chung đầu raĐầu ra của đoạn mã trên là - Array( [0] => Symfony\Component\Finder\SplFileInfo Object( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => css [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => css\test.css [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\css\test.css [fileName:SplFileInfo:private] => test.css ) [1] => Symfony\Component\Finder\SplFileInfo Object( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => favicon.ico [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\favicon.ico [fileName:SplFileInfo:private] => favicon.ico ) [2] => Symfony\Component\Finder\SplFileInfo Object( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => images [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => images\flower.jpg [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\images\flower.jpg [fileName:SplFileInfo:private] => flower.jpg ) [3] => Symfony\Component\Finder\SplFileInfo Object( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => index.php [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\index.php [fileName:SplFileInfo:private] => index.php ) [4] => Symfony\Component\Finder\SplFileInfo Object( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => robots.txt [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\robots.txt [fileName:SplFileInfo:private] => robots.txt ) ) ví dụ 2Để có được tất cả các hình ảnh từ thư mục chung đầu raĐầu ra cho ở trên là như sau Array( [0] => Symfony\Component\Finder\SplFileInfo Object( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => flower.jpg [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\images\flower.jpg [fileName:SplFileInfo:private] => flower.jpg ) ) ví dụ 3Để lấy tất cả các tệp CSS từ thư mục chung - đầu raĐầu ra của đoạn mã trên là - Array( [0] => Symfony\Component\Finder\SplFileInfo Object ( [relativePath:Symfony\Component\Finder\SplFileInfo:private] => [relativePathname:Symfony\Component\Finder\SplFileInfo:private] => test.css [pathName:SplFileInfo:private] => C:\xampp\htdocs\laraveltest\public\css\test.css [fileName:SplFileInfo:private] => test.css ) ) Ví dụ 4Để lấy tất cả các tệp từ thư mục chung bằng phương thức scandir() - đầu raĐầu ra của đoạn mã trên là - ________số 8_______Để lấy tất cả các tệp trong một thư mục, bạn có thể sử dụng phương thức "tệp ()" có sẵn từ mặt tiền "Bộ nhớ". Chạy mã bên dưới sẽ trả về một mảng các tệp trong thư mục bạn đã chỉ định
|