Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is file_exists in PHP?

Sheza Munir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

PHP offers many functions for file manipulation. The file_exists function checks if a file or directory exists at the specified path.

Syntax

The syntax for file_exists function is shown below:

file_exists(string $path): bool

Parameters

The file_exists function takes only one parameter:

  • path: This is a required parameter. This is a string that specifies the path to the file or directory to check.

The results of this function are stored in the cache. You can use the clearstatcache function to clear the cache.

Return value

The function returns a bool value, true if the file or directory exists at the specified path, and returns false if it does not.

The working of file_exists function

Code

The following code shows how we can use the file_exists function:

main.php
test.txt
<?php
if (file_exists("test.txt")) {
echo "File exists.\n";
}
?>

RELATED TAGS

php

CONTRIBUTOR

Sheza Munir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring