Làm cách nào để kiểm tra đường dẫn của tệp trong php?

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ệ

  1. 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
  2. Đố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 : 1
6

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
7

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
8

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
9
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
0
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
1______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 : 1
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 : 1
7

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
3

đầ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 : 1
6

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
7

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
8

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
7
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
8
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
0
1
0

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
7

1
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 : 1
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 : 1
0
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
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 : 1
7
1
7

1
8

1
9
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
9
1
1
1
0

1
3

1
4

1
8

1
9
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
9
1
8
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
7
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
60

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
61____262

1
3

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
7

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
3

đầ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

Làm cách nào để tìm đường dẫn của tệp trong PHP?

Cú pháp. $filename = pathinfo[path]; Ví dụ. Ví dụ này giải thích hàm pathinfo[] sẽ trả về thông tin về đường dẫn.

Làm cách nào để sử dụng __ dir __ trong PHP?

Có thể sử dụng __DIR__ để lấy thư mục làm việc của mã hiện tại . Nó đã được giới thiệu trong PHP bắt đầu từ phiên bản 5. 3. Nó tương tự như sử dụng dirname[__FILE__]. Thông thường, nó được sử dụng để bao gồm các tệp khác có trong một tệp được bao gồm.

Làm cách nào để xác định đường dẫn trong PHP?

ini, hãy làm theo các bước sau. .
mở php. ini trong trình chỉnh sửa. .
Thêm dòng sau vào php. tập tin ini. Thay thế tên người dùng bằng tên người dùng Dịch vụ lưu trữ A2 của bạn và thay thế thư mục bao gồm bằng tên của thư mục bao gồm. bao_path = ". /home/tên người dùng/gồm_thư mục"
Lưu các tập tin. Đường dẫn bao gồm hiện được đặt

Chủ Đề