當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP SplFileInfo getFileInfo()用法及代碼示例


SplFileInfo::getFileInfo()函數是PHP中的標準PHP庫(SPL)的內置函數,用於獲取文件的文件信息。

用法:

SplFileInfo::getFileInfo( $class )

參數:該函數接受可選的單個參數$class。它用於指定splfile派生類的名稱。


返回值:此函數返回SplFileInfo對象。

以下示例程序旨在說明PHP中的SplFileInfo::getFileInfo()函數:

程序1:

<?php 
  
// PHP Program to illustrate  
// Splfileinfo::getFileInfo() function 
   
// Create new SPlFileInfo Object 
$file = new SplFileInfo("gfg.txt"); 
   
// Print result 
var_dump( $file->getFileInfo()); 
   
?>
輸出:
object(SplFileInfo)#2 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(7) "gfg.txt"
  ["fileName":"SplFileInfo":private]=>
  string(7) "gfg.txt"
}

程序2:

<?php 
  
// PHP program to use array to check 
// multiple files 
$GFG = array ( 
    "/home/rajvir/Desktop/GeeksforGeeks/dummy.php", 
    "/home/rajvir/Desktop/gfg.txt", 
    "/var/www/html/gfg.php", 
    "demo.c"
); 
    
foreach ($GFG as $file_name) { 
        
    // Create new SPlFileInfo Object 
    $file = new SplFileInfo($file_name); 
        
    // Print result 
    var_dump($file->getFileInfo()); 
    echo "</br>"; 
} 
?>
輸出:
object(SplFileInfo)#2 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(44) "/home/rajvir/Desktop/GeeksforGeeks/dummy.php"
  ["fileName":"SplFileInfo":private]=>
  string(9) "dummy.php"
}
object(SplFileInfo)#1 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(28) "/home/rajvir/Desktop/gfg.txt"
  ["fileName":"SplFileInfo":private]=>
  string(7) "gfg.txt"
}
object(SplFileInfo)#2 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(21) "/var/www/html/gfg.php"
  ["fileName":"SplFileInfo":private]=>
  string(7) "gfg.php"
}
object(SplFileInfo)#1 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(6) "demo.c"
  ["fileName":"SplFileInfo":private]=>
  string(6) "demo.c"
}

參考: http://php.net/manual/en/splfileinfo.getfileinfo.php



相關用法


注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | SplFileInfo getFileInfo() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。