Đây là một lớp lót nhanh chóng và đơn giản để chỉ liệt kê các tệp. Vì người dùng chỉ muốn liệt kê các tệp, nên không cần phải quét thư mục và trả về tất cả các nội dung và loại trừ các thư mục. Chỉ cần nhận các tập tin thuộc bất kỳ loại hoặc loại cụ thể. Sử dụng * để trả về tất cả các tệp bất kể phần mở rộng hoặc nhận các tệp có tiện ích mở rộng cụ thể bằng cách thay thế * bằng tiện ích mở rộng.
Nhận tất cả các tệp bất kể phần mở rộng:
$files = glob[$dir . DIRECTORY_SEPARATOR . "*"];
Nhận tất cả các tệp với phần mở rộng PHP:
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
Nhận tất cả các tệp với tiện ích mở rộng JS:
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
Tôi sử dụng những thứ sau cho các trang web của mình:
function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
Cách sử dụng :
$files = fileList[$configData->includesDirectory, ''];
Với chức năng tùy chỉnh của tôi, tôi có thể bao gồm một phần mở rộng hoặc để trống. Ngoài ra, tôi có thể quên đặt. Trước khi mở rộng và nó sẽ thành công.
Nerbert ¶
Fatpratmatt Dot tại dot gmail dot com ¶ — List files and directories inside the specified path
14 năm trước
Simon Dot Riget tại Gmail Dot Com ¶[string $directory
, int $sorting_order
= SCANDIR_SORT_ASCENDING
, ?resource $context
=
0]: array|false$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
6 năm trước
telefoontoestel59 tại hotmail dot comThư mục sẽ được quét.
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
2Theo mặc định, thứ tự được sắp xếp theo thứ tự theo thứ tự tăng dần. Nếu
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
2 tùy chọn được đặt thành $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
4, thì thứ tự sắp xếp là theo thứ tự bảng chữ cái theo thứ tự giảm dần. Nếu nó được đặt thành $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
5 thì kết quả sẽ không được phân loại.$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
4, then the sort order is alphabetical in descending order. If it is set to
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
5 then the result is unsorted. $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
6Để biết mô tả về tham số
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
6, hãy tham khảo phần luồng của hướng dẫn.Trả về giá trị
Trả về một mảng tên tệp thành công, hoặc
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
8 khi thất bại. Nếu $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
1 không phải là một thư mục, thì boolean $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
8 được trả về và lỗi của cấp $files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
1 được tạo ra.array of filenames on success, or $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
8 on failure. If $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
1 is not a directory,
then boolean $files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
8 is returned, and an error of level $files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
1 is generated. Thay đổi
8.0.0 | 6 bây giờ là vô hiệu. |
Ví dụ
Ví dụ #1 ví dụ scandir [] đơn giảnscandir[] example
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
3Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]
Ghi chú
Mẹo
Một URL có thể được sử dụng như một tên tệp với chức năng này nếu các giấy gói fopen đã được bật. Xem fopen [] để biết thêm chi tiết về cách chỉ định tên tệp. Xem các giao thức và trình bao bọc được hỗ trợ để biết các liên kết đến thông tin về những khả năng mà các trình bao bọc khác nhau có, ghi chú về việc sử dụng của chúng và thông tin về bất kỳ biến được xác định trước mà họ có thể cung cấp.fopen[] for more details on how to specify the filename. See the Supported Protocols and Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.
Xem thêm
- opendir [] - tay cầm thư mục mở
- readDir [] - Đọc mục nhập từ tay cầm thư mục
- glob [] - Tìm tên đường dẫn khớp với một mẫu
- is_dir [] - cho biết tên tệp có phải là thư mục
- Sắp xếp [] - Sắp xếp một mảng theo thứ tự tăng dần
Dwieeb tại gmail dot com ¶
10 năm trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
4$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
5$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6CoolBikram0 tại Gmail Dot Com ¶ ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
7$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
8$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
9mmda dot nl tại gmail dot com ¶ ¶
10 năm trước
function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
0function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
1function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
2function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
3CoolBikram0 tại Gmail Dot Com ¶ ¶
11 thàng trước
function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
4mmda dot nl tại gmail dot com ¶ ¶
Thông tin tại Ghi chú chấm không ¶
function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
54 năm trước ¶
10 năm trước
function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
6function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
7$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6CoolBikram0 tại Gmail Dot Com ¶ ¶
Thông tin tại Ghi chú chấm không ¶
function fileList[string $directory, string $extension=""] :array
{
$filetype = '*';
if[!empty[$extension] && mb_substr[$extension, 0, 1, "UTF-8"] != '.']:
$filetype .= '.' . $extension;
else:
$filetype .= $extension;
endif;
return glob[$directory . DIRECTORY_SEPARATOR . $filetype];
}
9$files = fileList[$configData->includesDirectory, ''];
0$files = fileList[$configData->includesDirectory, ''];
1$files = fileList[$configData->includesDirectory, ''];
24 năm trước ¶
EEP2004 tại UKR DOT Net
$files = fileList[$configData->includesDirectory, ''];
3$files = fileList[$configData->includesDirectory, ''];
4$files = fileList[$configData->includesDirectory, ''];
5$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
68 năm trước ¶
EEP2004 tại UKR DOT Net
$files = fileList[$configData->includesDirectory, ''];
7$files = fileList[$configData->includesDirectory, ''];
8$files = fileList[$configData->includesDirectory, ''];
9Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]0
8 năm trước ¶
Kodlee tại Kodleeshare Dot Net
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]1
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]2
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]3
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6gambit_642 tại hotmaildotcom ¶ ¶
csaba tại alum dot mit dot edu ¶
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]5
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]6
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
617 năm trước ¶
10 năm trước
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]8
Array [ [0] => . [1] => .. [2] => bar.php [3] => foo.txt [4] => somedir ] Array [ [0] => somedir [1] => foo.txt [2] => bar.php [3] => .. [4] => . ]9
$directory
0
$directory
1
$directory
2
$directory
3
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6CoolBikram0 tại Gmail Dot Com ¶ ¶
10 năm trước
$directory
5
CoolBikram0 tại Gmail Dot Com ¶ ¶
11 thàng trước
$directory
6
$directory
7
$directory
8
$directory
9
$sorting_order
0
$sorting_order
1
$sorting_order
2
$sorting_order
3
$sorting_order
4
$sorting_order
5
$sorting_order
6
$sorting_order
7mmda dot nl tại gmail dot com ¶ ¶
csaba tại alum dot mit dot edu ¶
$sorting_order
8
$sorting_order
9
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
617 năm trước ¶
Pawel Dlugosz ¶
SCANDIR_SORT_ASCENDING
1
SCANDIR_SORT_ASCENDING
2
SCANDIR_SORT_ASCENDING
3
SCANDIR_SORT_ASCENDING
4
SCANDIR_SORT_ASCENDING
5
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6Stan P. van de Burgt ¶ ¶
18 năm trước
SCANDIR_SORT_ASCENDING
7
SCANDIR_SORT_ASCENDING
8
SCANDIR_SORT_ASCENDING
9
$context
0Artmanniako tại Gmail Dot Com ¶ ¶
3 năm trước
$context
1
$context
2
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6Fazle Dot Elahee tại Gmail Dot Com ¶ ¶
3 năm trước
$context
4
$context
5
$context
6
$context
7Fazle Dot Elahee tại Gmail Dot Com ¶ ¶
Thông tin tại Ghi chú chấm không ¶
$context
8
$context
9
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
00$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
01$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
02$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
03$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
04$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
05$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
64 năm trước ¶
10 năm trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
07CoolBikram0 tại Gmail Dot Com ¶ ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
08$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
09$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6mmda dot nl tại gmail dot com ¶ ¶
Thông tin tại Ghi chú chấm không ¶
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
11$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
12$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
13$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
64 năm trước ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
15$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
16$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
17$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6mmda dot nl tại gmail dot com ¶ ¶
EEP2004 tại UKR DOT Net
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
19$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
20$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
21$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
22$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
68 năm trước ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
24mmda dot nl tại gmail dot com ¶ ¶
Thông tin tại Ghi chú chấm không ¶
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
25$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
26$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
27$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
284 năm trước ¶
EEP2004 tại UKR DOT Net
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
298 năm trước ¶
csaba tại alum dot mit dot edu ¶
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
30$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
31$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
617 năm trước ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
33$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
34$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
35$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
36$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6mmda dot nl tại gmail dot com ¶ ¶
Thông tin tại Ghi chú chấm không ¶
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
38$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
39$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
40$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
414 năm trước ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
42$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
43$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
44$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
45$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
46$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6mmda dot nl tại gmail dot com ¶ ¶
11 thàng trước
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
48$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
49$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
50$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6mmda dot nl tại gmail dot com ¶ ¶
Pawel Dlugosz ¶
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
52$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
53$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
54$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
554 năm trước ¶
EEP2004 tại UKR DOT Net
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
56$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
57$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
68 năm trước ¶
Kodlee tại Kodleeshare Dot Net
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
59gambit_642 tại hotmaildotcom ¶ ¶
EEP2004 tại UKR DOT Net
$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
60$files = glob[$dir . DIRECTORY_SEPARATOR . "*.php"];
61$files = glob[$dir . DIRECTORY_SEPARATOR . "*.js"];
6