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

Tutorial PHP Básico

Tutorial PHP Avançado

PHP & MySQL

Manual de Referência PHP

Uso e exemplo da função PHP file_exists()

PHP Filesystem Referência Manual

A função file_exists() pode verificar se um arquivo ou diretório existe. Se o arquivo ou diretório existir, esta função retorna true, caso contrário, retorna false.

Sintaxe

bool file_exists ( string $filename )

Esta função pode verificar se um arquivo ou diretório existe.

Exemplo online

<?php
   $filename = "/PhpProject/sample.txt"
   if(file_exists($filename)) {
      echo "Arquivo $filename existe";
   } else {
      echo "Arquivo $filename não existe";
   }
?>

Resultado de saída

Arquivo /PhpProject/sample.txt existe

PHP Filesystem Referência Manual