file_exists() / is_file() / is_dir()
function
Check if a file or directory exists. is_file() confirms a regular file; is_dir() confirms a directory.
Syntax
file_exists(string $filename): bool
Example
php
<?php
if (file_exists('config.php')) {
require 'config.php';
}
if (!is_dir('uploads')) {
mkdir('uploads', 0755, true);
}
$ext = strtolower(pathinfo($_FILES['f']['name'], PATHINFO_EXTENSION));
if (!in_array($ext, ['jpg','png','gif'])) exit('Invalid type');