PHP - Fonction file_exists ()

La fonction file_exists () peut vérifier si un fichier ou un répertoire existe ou non. Cette fonction renvoie true si le fichier ou le répertoire existe, sinon renvoie false.

Syntaxe

bool file_exists ( string $filename )

Cette fonction peut vérifier si un fichier ou un répertoire existe.

Exemple

<?php
   $filename = "/PhpProject/sample.txt";

   if(file_exists($filename)) {
      echo "The file $filename exists";
   } else {
      echo "The file $filenamedoes not exist";
   }
?>

Production

The file /PhpProject/sample.txt exists