file_exists

(PHP 3, PHP 4 )

file_exists -- ファイルまたはディレクトリが存在するかどうか調べる

説明

bool file_exists ( string filename)

filenameで指定したファイルまたはディレクトリ が存在すればTRUEを返し、そうでなければFALSEを返します。

ウインドウズ共有の使用 ウインドウズ上でネットワーク共有上のファイルを調べるには、 //computername/share/filenameまたは \\computername\share\filenameを使用して下さい。

例 1あるファイルが存在するかどうか調べる

<?php
$filename = '/path/to/foo.txt';

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

注意この関数の結果は キャッシュされます。詳細は、clearstatcache() を参照 して下さい。

注意この関数では、 リモートファイルを 使用することはできません。これは、処理されるファイルがサーバーの ファイルシステムによりアクセスできる必要があるためです。

is_readable(), is_writable(), is_file(), file()も参照して下 さい。