Home >Backend Development >PHP Problem >How to check if a file exists in php

How to check if a file exists in php

coldplay.xixi
coldplay.xixiOriginal
2020-08-06 10:11:287723browse

How to query whether a file exists in php: Use the built-in function [file_exists] to determine whether the file exists. The code is [if(file_exists($file)){echo "In the current directory, file".$file ."exist"}】.

How to check if a file exists in php

How to query whether a file exists in php:

There are built-in functions to determine whether a file or directory exists

file_exists:Whether the file exists

$file = "check.txt";
if(file_exists($file))
{
    echo "当前目录中,文件".$file."存在";
}
else
{
     echo "当前目录中,文件".$file."不存在";
}

is_dir:Whether the directory exists

$dir = "c:/datacheck";
if(is_dir($dir))
{
    echo "当前目录下,目录".$dir."存在";
}
else
{
     echo "当前目录下,目录".$dir."不存在";
}

Related learning recommendations: php programming (video)

The above is the detailed content of How to check if a file exists in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more