[Php 4, Php 5, Php 7, Php 8]
file_exists - kiểm tra xem một tệp hoặc thư mục có tồn tại không — Checks whether a file or directory exists
Sự mô tả
File_Exists [Chuỗi $filename
]: Bool[string $filename
]: bool
Thông số
filename
Đường dẫn đến tệp hoặc thư mục.
Trên Windows, sử dụng // Computername/Share/FileName hoặc \\ Computername \ Share \ FileName để kiểm tra các tệp trên chia sẻ mạng.
Trả về giá trị
Trả về true
Nếu tệp hoặc thư mục được chỉ định bởi filename
tồn tại; false
nếu không.true
if the file or directory specified by filename
exists; false
otherwise.
Ghi chú::
Hàm này sẽ trả về
false
cho các liên kết symlink trỏ đến các tệp không tồn tại.false
for symlinks pointing to non-existing files.
Ghi chú::
Hàm này sẽ trả về
false
cho các liên kết symlink trỏ đến các tệp không tồn tại.
Kiểm tra được thực hiện bằng cách sử dụng UID/GID thực sự thay vì hiệu quả.: Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB.
Errors/Exceptions
Lưu ý: Vì loại số nguyên của PHP được ký kết và nhiều nền tảng sử dụng số nguyên 32 bit, một số hàm hệ thống tập tin có thể trả về kết quả bất ngờ cho các tệp lớn hơn 2GB.E_WARNING
is emitted.
Sau khi thất bại, một E_WARNING
được phát ra.
Ví dụ
Ví dụ số 1 kiểm tra xem một tệp có tồn tại không
Ghi chú: The results of this function are cached. See clearstatcache[] for more details.
Lưu ý: Kết quả của chức năng này được lưu trong bộ nhớ cache. Xem ClearStatCache [] để biết thêm chi tiết.
- Xem thêm
- is_readable [] - cho biết liệu một tệp có tồn tại hay không và có thể đọc được không
- is_writable [] - cho biết liệu tên tệp có thể ghi được không
- is_file [] - cho biết liệu tên tệp có phải là tệp thông thường không
- file [] - đọc toàn bộ tệp vào một mảng
Splfileinfo ¶
Maurice tại Idify Dot NL ¶
filename
0
filename
1
filename
2
14 năm trước ¶
ziptwipi tại goioia dot com ¶
filename
3
6 năm trước ¶
Welkom tại Remconijhuis dot nl ¶
filename
4
8 năm trước ¶
Vernon tại KesnerDesigns Dot Net ¶
filename
5
filename
6
filename
215 năm trước ¶
Vernon tại KesnerDesigns Dot Net ¶
filename
8
filename
9
true
0
true
1
filename
215 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
true
3
true
4
true
5
true
6
filename
2jag ¶ ¶
3 năm trước
true
8
true
9
filename
0
filename
1
filename
2
filename
3
filename
2Vcoletti tại Tiscali Dot it ¶ ¶
Vernon tại KesnerDesigns Dot Net ¶
filename
5
filename
6
filename
215 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
filename
8
jag ¶ ¶
3 năm trước
filename
9
false
0
false
1
false
2
false
3
false
4
false
5
filename
2Vcoletti tại Tiscali Dot it ¶ ¶
Vernon tại KesnerDesigns Dot Net ¶
false
7
false
8
filename
215 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
false
0
false
1
false
2
false
3
jag ¶ ¶
Vernon tại KesnerDesigns Dot Net ¶
false
4
false
5
false
6
false
715 năm trước ¶
Maurice tại Idify Dot NL ¶
false
8
false
9
E_WARNING
0
E_WARNING
1
E_WARNING
2
filename
214 năm trước ¶
ziptwipi tại goioia dot com ¶
E_WARNING
4
E_WARNING
5
filename
26 năm trước ¶
Welkom tại Remconijhuis dot nl ¶
E_WARNING
7
E_WARNING
8
filename
28 năm trước ¶
Vernon tại KesnerDesigns Dot Net ¶
8
file_exists[$filename]] {
9
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
filename
00
filename
01
filename
026 năm trước ¶
ziptwipi tại goioia dot com ¶
filename
03
filename
04
filename
05
filename
066 năm trước ¶
ziptwipi tại goioia dot com ¶
filename
07
6 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
filename
08
filename
09
filename
10
filename
11
filename
12
filename
13
filename
14
filename
15jag ¶ ¶
ziptwipi tại goioia dot com ¶
filename
16
filename
17
filename
26 năm trước ¶
ziptwipi tại goioia dot com ¶
filename
19
filename
20
filename
21
filename
2