filemtime function

filemtime function သည် ဖိုင်၏ နောက်ဆုံးပြင်ဆင်ချိန် Unix timestamp ကို ပြန်ပေးသည်။ parameter တွင် ဖိုင်လမ်းကြောင်းကို ပေးရသည်။ ဖိုင်မရှိပါက function သည် false ကိုပြန်ပေးမည်။

Syntax

phpfilemtime(string $filename): int|false

ဥပမာ

လက်ရှိဖိုင်၏ ပြောင်းလဲချိန်ကိုရယူကြမည်။

php<?php
  $res = filemtime(__FILE__);
  echo $res;
?>

ကုဒ်အလုပ်လုပ်ပြီးနောက် ရလဒ်။

php1672531200

ဥပမာ

ဖိုင်ရှိ/မရှိ စစ်ဆေးပြီး ပြောင်းလဲချိန်ကို ပြသကြမည်။

php<?php
  $file = 'test.txt';
  if (file_exists($file)) {
    echo 'Last modified: ' . date('Y-m-d H:i:s', filemtime($file));
  } else {
    echo 'File not found';
  }
?>

ကုဒ်အလုပ်လုပ်ပြီးနောက် ရလဒ်။

php'Last modified: 2023-01-01 12:00:00'

ဥပမာ

ဖိုင်နှစ်ခု၏ ပြောင်းလဲချိန်များကို နှိုင်းယှဉ်ကြည့်ကြမည်။

php<?php
  $file1 = 'file1.txt';
  $file2 = 'file2.txt';
  
  if (filemtime($file1) > filemtime($file2)) {
    echo 'File1 is newer';
  } else {
    echo 'File2 is newer or equal';
  }
?>

ကုဒ်အလုပ်လုပ်ပြီးနောက် ရလဒ်။

php'File1 is newer'

ဆက်လက်ကြည့်ရှုရန်

  • filectime function,
    ဖိုင်ဖန်တီးချိန်ကို ပြန်ပေးသည်
  • fileatime function,
    အသုံးပြုချိန်ကို ပြန်ပေးသည်
  • touch function,
    ပြင်ဆင်ချိန်ကို ပြောင်းလဲပေးသည်