Home >Backend Development >PHP Problem >How to check if a file exists in php
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 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!