English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP file_exists() Function Usage and Example

PHP Filesystem Reference Manual

The file_exists() function can check if a file or directory exists. If the file or directory exists, this function returns true, otherwise it returns false.

Syntax

bool file_exists ( string $filename )

This function can check if a file or directory exists.

Online Example

<?php
   $filename = "/PhpProject/sample.txt"
   if(file_exists($filename)) {
      echo "File $filename exists";
   } else {
      echo "File $filename does not exist";
   }
?>

Output Result

File /PhpProject/sample.txt exists

PHP Filesystem Reference Manual