当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP DirectoryIterator getCTime()用法及代码示例


DirectoryIterator::getCTime()函数是PHP中的内置函数,用于获取当前DirectoryIterator项的inode更改时间。

用法:

int DirectoryIterator::getCTime( void )

参数:该函数不接受任何参数。


返回值:此函数以Unix时间戳格式返回文件的最后更改时间。

以下示例程序旨在说明PHP中的DirectoryIterator::getCTime()函数:

示例1:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs while directory is valid 
while ($directory->valid()) { 
  
    // Check if the element is directory 
    if ($directory->isDir()) { 
  
        // Store the current element 
        $file = $directory->current(); 
  
        // Display the file name and  
        // inode change time 
        echo $file->getFilename() . " | CTime: "
                . $directory->getCTime() . "<br>"; 
    } 
  
    // Move to the next element 
    $directory->next(); 
} 
?> 

输出:

. | CTime: 1574350718
.. | CTime: 1574350715
dashboard | CTime: 1574350718
img | CTime: 1574350718
webalizer | CTime: 1574350718
xampp | CTime: 1574350718

示例2:

<?php 
  
// Create a directory Iterator 
$directory = new DirectoryIterator(dirname(__FILE__)); 
  
// Loop runs for each element of directory 
foreach($directory as $dir) { 
      
    // Store the current element of directory 
    $file = $directory->current(); 
      
    // Display the key, filename and  
    // its inode change time 
    echo $dir->key() . " => " .  
        $file->getFilename() . " | CTime: " . 
        $dir->getCTime() . "<br>"; 
} 
?>

输出:

0 => . | CTime: 1574350718
1 => .. | CTime: 1574350715
2 => applications.html | CTime: 1574350724
3 => bitnami.css | CTime: 1574350724
4 => dashboard | CTime: 1574350718
5 => favicon.ico | CTime: 1574350724
6 => geeks.PNG | CTime: 1574478578
7 => gfg.php | CTime: 1574351394
8 => img | CTime: 1574350718
9 => index.php | CTime: 1574350723
10 => webalizer | CTime: 1574350718
11 => xampp | CTime: 1574350718

注意:此函数的输出取决于服务器文件夹的内容。

参考: https://www.php.net/manual/en/directoryiterator.getctime.php



相关用法


注:本文由纯净天空筛选整理自jit_t大神的英文原创作品 PHP | DirectoryIterator getCTime() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。