PHP | file_exists( ) Function
The file_exists() function in PHP is an inbuilt function which is used to check whether a file or directory exists or not.
The path of the file or directory you want to check is passed as a parameter to the file_exists() function which returns True on success and False on failure.
Syntax:
file_exists($path)
Parameters: The file_exists() function in PHP accepts only one parameter $path. It specifies the path of the file or directory you want to check.
Return Value: It returns True on success and False on failure.
Errors And Exception:
- The file_exists() function returns False if the path specified points to non-existent files.
- For files larger than 2gb, some of the filesystem functions may give unexpected results since PHP’s integer type is signed and many platforms use 32bit integers.
Examples:
Input : echo file_exists('/user01/work/gfg.txt');
Output : 1
Input : $file_pointer = '/user01/work/gfg.txt';
if (file_exists($file_pointer)) {
echo "The file $file_pointer exists";
}else {
echo "The file $file_pointer does
not exists";
}
Output : 1
Below programs illustrate the file_exists() function.
Program 1:
<?php // checking whether file exists or not echo file_exists('/user01/work/gfg.txt'); ?> |
Output:
1
Program 2:
<?php // checking whether file exists or not $file_pointer = '/user01/work/gfg.txt'; if (file_exists($file_pointer)) { echo "The file $file_pointer exists"; } else { echo "The file $file_pointer does not exists"; } ?> |
Output:
1
Reference:
http://php.net/manual/en/function.file-exists.php
Recommended Posts:
- PHP | Ds\Map last() Function
- PHP | Ds\Map map() Function
- p5.js | red() function
- p5.js | tan() function
- p5.js | log() function
- p5.js | sin() function
- p5.js | cos() function
- p5.js | arc() Function
- PHP | pow( ) Function
- p5.js | str() function
- PHP | exp() Function
- PHP | next() Function
- PHP Ds\Set sum() Function
- p5.js | hex() function
- PHP Ds\Set get() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



