(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ụ
<?php
$filename = '/path/to/foo.txt';
if (
file_exists($filename)) {echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
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 ¶
filename0
filename1
filename214 năm trước ¶
ziptwipi tại goioia dot com ¶
filename3
6 năm trước ¶
Welkom tại Remconijhuis dot nl ¶
filename4
8 năm trước ¶
Vernon tại KesnerDesigns Dot Net ¶
filename5
filename6
filename215 năm trước ¶
Vernon tại KesnerDesigns Dot Net ¶
filename8
filename9
true0
true1
filename215 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
true3
true4
true5
true6
filename2jag ¶ ¶
3 năm trước
true8
true9
filename0
filename1
filename2
filename3
filename2Vcoletti tại Tiscali Dot it ¶ ¶
Vernon tại KesnerDesigns Dot Net ¶
filename5
filename6
filename215 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
filename8
jag ¶ ¶
3 năm trước
filename9
false0
false1
false2
false3
false4
false5
filename2Vcoletti tại Tiscali Dot it ¶ ¶
Vernon tại KesnerDesigns Dot Net ¶
false7
false8
filename215 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
false0
false1
false2
false3jag ¶ ¶
Maurice tại Idify Dot NL ¶
false4
false5
false6
false714 năm trước ¶
Maurice tại Idify Dot NL ¶
false8
false9
E_WARNING0
E_WARNING1
E_WARNING2
filename214 năm trước ¶
ziptwipi tại goioia dot com ¶
E_WARNING4
E_WARNING5
filename26 năm trước ¶
Welkom tại Remconijhuis dot nl ¶
E_WARNING7
E_WARNING8
filename28 năm trước ¶
Vernon tại KesnerDesigns Dot Net ¶
<?php
$filename = '/path/to/foo.txt';0
<?php
$filename = '/path/to/foo.txt';1
<?php
$filename = '/path/to/foo.txt';2
<?php
$filename = '/path/to/foo.txt';3
15 năm trước ¶
Welkom tại Remconijhuis dot nl ¶
<?php
$filename = '/path/to/foo.txt';5
<?php
$filename = '/path/to/foo.txt';6
8 năm trước ¶
Maurice tại Idify Dot NL ¶
<?php
$filename = '/path/to/foo.txt';8
<?php
$filename = '/path/to/foo.txt';9
14 năm trước ¶
Maurice tại Idify Dot NL ¶
if (1
if (2
if (3
if (4
if (5
if (6
filename214 năm trước ¶
Maurice tại Idify Dot NL ¶
if (8
if (9
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
0
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?> 1
14 năm trước ¶
Maurice tại Idify Dot NL ¶
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
2
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
3
14 năm trước ¶
ziptwipi tại goioia dot com ¶
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
5
6 năm trước ¶
ziptwipi tại goioia dot com ¶
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
6
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
7
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
8
file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
9
filename00
filename01
filename026 năm trước ¶
ziptwipi tại goioia dot com ¶
filename03
filename04
filename05
filename066 năm trước ¶
Bvazquez tại Siscomx Dot Com ¶
filename07
jag ¶ ¶
Bvazquez tại Siscomx Dot Com ¶
filename08
filename09
filename10
filename11
filename12
filename13
filename14
filename15jag ¶ ¶
ziptwipi tại goioia dot com ¶
filename16
filename17
filename26 năm trước ¶
ziptwipi tại goioia dot com ¶
filename19
filename20
filename21
filename2