How to check if a file exists in php

coldplay.xixi
Release: 2023-03-03 21:26:01
Original
7634 people have browsed it

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."不存在";
}
Copy after login

is_dir:Whether the directory exists

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

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!