Home > Article > Backend Development > How to determine whether the image exists in php
In PHP, you can use the file_exists() function to determine whether a picture exists. This function can detect whether a file or directory exists. The syntax format is "file_exists(lujing)"; if the picture file exists, it returns true. , otherwise return false.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use the file_exists() function To determine whether the image exists.
<?php header("Content-type:text/html;charset=utf-8"); $file = 'img.png'; if(file_exists($file)){ echo "图片文件 {$file} 存在!"; }else{ echo "图片文件 {$file} 不存在!"; } ?>
Output result:
Let’s take a brief look at the file_exists() function:
file_exists() function checks whether the file or directory is exist. Returns true if the specified file or directory exists, false otherwise.
Syntax: file_exists(path)
Parameter description is as follows:
path: required. Specifies the path to be checked.
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to determine whether the image exists in php. For more information, please follow other related articles on the PHP Chinese website!