$dir = '/path/to/directory'; if (!file_exists($dir)) { mkdir($dir, 0777, true); }
$file = '/path/to/file.txt'; $content = 'Hello, world!'; file_put_contents($file, $content);
$file = '/path/to/file.txt'; if (file_exists($file)) { // do something with the file } $dir = '/path/to/directory'; if (is_dir($dir)) { // do something with the directory }These examples show how to check if a file or directory exists on the server's filesystem using the functions `file_exists` and `is_dir`. These functions are a part of the PHP core library and do not require any additional package or library installation.