PHP.mk документација

filectime

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.filectime.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.filectime.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
filectime

Референца за `function.filectime.php` со подобрена типографија и навигација.

function.filectime.php

filectime

(PHP 4, PHP 5, PHP 7, PHP 8)

filectimeЈа добива времето на промена на инодот на датотеката

= NULL

filectime(string $filename): int|false

Ја добива времето на промена на инодот на датотеката.

Параметри

filename

Патека до датотеката.

Вратени вредности

Враќа време кога датотеката последно е променета, или false при неуспех. Времето се враќа како Unix временски печат.

Errors/Exceptions

Бидејќи типот на податоци integer во PHP е со знакот и многу платформи користат 32-битни integers, некои функции за датотечниот систем може да вратат неочекувани резултати за датотеки поголеми од 2GB. E_WARNING се емитува.

Примери

ако е овозможен колекторот за отпадоци, filectime() example

<?php

// outputs e.g. somefile.txt was last changed: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (
file_exists($filename)) {
echo
"$filename was last changed: " . date("F d Y H:i:s.", filectime($filename));
}

?>

Белешки

Забелешка:

Забелешка: Во повеќето Unix системи на датотеки, датотеката се смета за променета кога нејзините инодо податоци се променети; тоа е, кога дозволите, сопственикот, групата или други метаподатоци од инодот се ажурирани. Види исто така filemtime() (што е она што сакате да го користите кога сакате да креирате подножја „Последно изменето“ на веб-страници) и fileatime().

Забелешка:

Исто така, забележете дека во некои Unix текстови времето на промена (ctime) на датотеката се нарекува време на создавање на датотеката. Ова е погрешно. Не постои време на создавање за Unix датотеки во повеќето Unix системи на датотеки.

Забелешка:

информации заедно со

Забелешка: Имајте предвид дека резолуцијата на времето може да се разликува од еден датотечен систем до друг. clearstatcache() за повеќе детали.

Совети

Резултатите од оваа функција се кеширани. Погледнете some Од PHP 5.0.0, оваа функција може да се користи и со Поддржани протоколи и обвивки URL обвивки. Погледнете stat() за да се утврди кои обвивки поддржуваат

Види Исто така

  • filemtime() - Добива информации за датотека користејќи отворен покажувач на датотека

Белешки од корисници 9 белешки

StevieMc на example dot com
19 години пред
This method gets all the files in a directory, and echoes them in the order of the date they were added (by ftp or whatever).

<?PHP
function dirList ($directory, $sortOrder){

    //Get each file and add its details to two arrays
    $results = array();
    $handler = opendir($directory);
    while ($file = readdir($handler)) {  
        if ($file != '.' && $file != '..' && $file != "robots.txt" && $file != ".htaccess"){
            $currentModified = filectime($directory."/".$file);
            $file_names[] = $file;
            $file_dates[] = $currentModified;
        }    
    }
       closedir($handler);

    //Sort the date array by preferred order
    if ($sortOrder == "newestFirst"){
        arsort($file_dates);
    }else{
        asort($file_dates);
    }
    
    //Match file_names array to file_dates array
    $file_names_Array = array_keys($file_dates);
    foreach ($file_names_Array as $idx => $name) $name=$file_names[$name];
    $file_dates = array_merge($file_dates);
    
    $i = 0;

    //Loop through dates array and then echo the list
    foreach ($file_dates as $file_dates){
        $date = $file_dates;
        $j = $file_names_Array[$i];
        $file = $file_names[$j];
        $i++;
            
        echo  "File name: $file - Date Added: $date. <br/>"";        
    }

}
?>

I hope this is useful to somebody.
website на us dot kaspersky dot com
пред 18 години
Line 37 of the code above has an error.

echo  "File name: $file - Date Added: $date. <br/>"";  

There is an extra "  after the <br/> that needs to be deleted in order for this code to work.
javi на live dot com
пред 17 години
Filemtime seems to return the date of the EARLIEST modified file inside a folder, so this is a recursive function to return the date of the LAST (most recently) modified file inside a folder.

<?php

// Only take into account those files whose extensions you want to show.
$allowedExtensions = array(
  'zip',
  'rar',
  'pdf',
  'txt'
);

function filemtime_r($path)
{
    global $allowedExtensions;
    
    if (!file_exists($path))
        return 0;
    
    $extension = end(explode(".", $path));     
    if (is_file($path) && in_array($extension, $allowedExtensions))
        return filemtime($path);
    $ret = 0;
    
     foreach (glob($path."/*") as $fn)
     {
        if (filemtime_r($fn) > $ret)
            $ret = filemtime_r($fn);    
            // This will return a timestamp, you will have to use date().
     }
    return $ret;    
}

?>
coolkoon на gmail dot com
пред 15 години
You should avoid feeding the function files without a path. This applies for filemtime() and possibly fileatime() as well. If you omit the path the command will fail with the warning "filectime(): stat failed for filename.php".
m dot rabe на directbox dot com
пред 16 години
Under Windows you can use fileatime() instead of filectime().
chuck точка reeves на gmail точка com
пред 18 години
filectime running on windows reading a file from a samba share, will still show the last modified date.
faketruth на yandex dot ru
пред 10 години
If you need file creation time on Mac OS X:

<?php
if ($handle = popen('stat -f %B ' . escapeshellarg($filename), 'r')) {
    $btime = trim(fread($handle, 100));
    echo strftime("btime: %Y.%m.%d %H:%M:%S\n", $btime);
    pclose($handle);
}
?>
soapergem на gmail точка com
пред 16 години
Note that on Windows systems, filectime will show the file creation time, as there is no such thing as "change time" in Windows.
laurent dot pireyn на wanadoo dot be
figroc at gmail dot com
If you use filectime with a symbolic link, you will get the change time of the file actually linked to. To get informations about the link self, use lstat.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.