//擷取檔案的主要資訊。 $file = "data.txt"; if(is_dir($file)) { echo "檔案 $file 是個目錄"; echo "<br/>"; } else { echo "檔案 $file 不是目錄"; echo "<br/>"; } if(is_file($file)) { echo "檔案 $file 是一個普通檔案"; echo "<br/>"; } if(is_readable($file)) { echo "檔案 $file 是可讀的"; echo "<br/>"; } else { echo "檔案 $file 是不可讀的"; echo "<br/>"; } if(is_writeable($file)) { echo "檔案 $file 是可寫的"; echo "<br/>"; } else { echo "檔案 $file 是不可寫的"; echo "<br/>"; } //判斷檔案的性質。 $path = "/home/prog/php/sayhello.php"; $file_name = basename($path); $dir_name = dirname($path); echo "完整路徑:".$path; echo "<hr>"; echo "<br/>"; echo "其中目錄名為:".$dir_name; echo "<br/>"; echo "其中檔案名稱為:".$file_name; echo "<br/>"; //擷取檔案名稱和目錄名。 $file = "data.txt"; $dir = "info/newdata"; if(file_exists($file)) { echo "目前的目錄中,檔案".$file."存在"; echo "<br/>"; } else { echo "目前的目錄中,檔案".$file."不存在"; echo "<br/>"; } echo "<br/>"; echo "<hr>"; echo "<br/>"; if(file_exists($dir)) { echo "目前的目錄下,目錄".$dir."存在"; echo "<br/>"; } else { echo "目前的目錄下,目錄".$dir."不存在"; echo "<br/>"; } |