Hàm file_exists[] trong PHP là một hàm có sẵn dùng để kiểm tra xem một tập tin hoặc thư mục có tồn tại hay không
Đường dẫn của tệp hoặc thư mục bạn muốn kiểm tra được truyền dưới dạng tham số cho hàm file_exists[] trả về True nếu thành công và Sai nếu không thành công
cú pháp
file_exists[$path]
Thông số. Hàm file_exists[] trong PHP chỉ chấp nhận một tham số $path. Nó chỉ định đường dẫn của tệp hoặc thư mục bạn muốn kiểm tra
Giá trị trả về. Nó trả về True khi thành công và Sai khi thất bại
lỗi và ngoại lệ
- Hàm file_exists[] trả về Sai nếu đường dẫn chỉ định trỏ tới các tệp không tồn tại
- Đối với các tệp lớn hơn 2gb, một số chức năng của hệ thống tệp có thể cho kết quả không mong muốn do loại số nguyên của PHP được ký và nhiều nền tảng sử dụng số nguyên 32 bit
ví dụ
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 1
Các chương trình bên dưới minh họa hàm file_exists[]
chương trình 1
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 16
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 18
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 19
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 10
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 11______10
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 11
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 13
đầu ra
1
chương trình 2
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 16
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 18
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 18
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 10
10
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
12
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 11
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 10
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 11
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
17
18
19
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 19
11
10
13
14
18
19
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 19
18
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 160
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 161____262
13
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 17
Input : echo file_exists['/user01/work/gfg.txt']; Output : 1 Input : $file_pointer = '/user01/work/gfg.txt'; if [file_exists[$file_pointer]] { echo "The file $file_pointer exists"; }else { echo "The file $file_pointer does not exists"; } Output : 13
đầu ra
1
Tham khảo.
http. //php. net/thủ công/vi/chức năng. File tồn tại. php
PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này