(PHP 4, PHP 5, PHP 7)
file_exists — Checks whether a file or directory exists
$filename
) : boolChecks whether a file or directory exists.
filename
Path to the file or directory.
On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares.
Returns true
if the file or directory specified by
filename
exists; false
otherwise.
Notă:
This function will return
false
for symlinks pointing to non-existing files.
Notă:
The check is done using the real UID/GID instead of the effective one.
Notă: Deoarece tipul întreg al PHP este cu semn și multe platforme utilizează întregi de 32 de biți, unele funcții ale sistemului de fișiere pot întoarce rezultate neașteptate pentru fișiere ce depășesc 2GB.
Example #1 Testing whether a file exists
<?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
În cazul eșecului este emis un E_WARNING
.
Notă: Rezultatele acestei funcții sunt stocate în cache. Accesați clearstatcache() pentru mai multe detalii.
Începând cu PHP 5.0.0 această funcție poate fi utilizată de asemenea cu unele învelișuri URL. Referiți-vă la Supported Protocols and Wrappers pentru a determina care învelișuri susțin familia de funcționalitate stat().