Home  >  Article  >  Backend Development  >  How to determine whether the image exists in php

How to determine whether the image exists in php

青灯夜游
青灯夜游Original
2021-09-16 19:11:513229browse

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.

How to determine whether the image exists in php

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 = &#39;img.png&#39;;
if(file_exists($file)){
    echo "图片文件 {$file} 存在!";
}else{
    echo "图片文件 {$file} 不存在!";
}
?>

Output result:

How to determine whether the image exists in php

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!

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