file_exists function

file_exists function သည် ပေးထားသော path တစ်ခုတွင် ဖိုင် သို့မဟုတ် ဒိုင်ရက်တရီ ရှိ/မရှိ စစ်ဆေးပေးသည်။ ဖိုင် သို့မဟုတ် ဒိုင်ရက်တရီ ရှိပါက function သည် true ပြန်ပေးပြီး၊ မရှိပါက false ပြန်ပေးသည်။ Function ၏ parameter အဖြစ် ဖိုင်သို့ absolute သို့မဟုတ် relative path ပါသော string တစ်ခုကို ပေးရသည်။

Syntax

phpfile_exists(string $filename): bool

ဥပမာ

လက်ရှိ ဒိုင်ရက်တရီအတွင်းရှိ 'test.txt' ဖိုင် ရှိ/မရှိ စစ်ဆေးကြည့်ရအောင်။

php<?php
  $res = file_exists('test.txt');
  var_dump($res);
?>

ကုဒ်ကို run လိုက်ရင် ရလာဒ် (ဖိုင် ရှိခဲ့ရင်)။

phptrue

ဥပမာ

မရှိသော ဖိုင် တစ်ခု ရှိ/မရှိ စစ်ဆေးကြည့်ရအောင်။

php<?php
  $res = file_exists('nonexistent_file.txt');
  var_dump($res);
?>

ကုဒ်ကို run လိုက်ရင် ရလာဒ်။

phpfalse

ဥပမာ

ဒိုင်ရက်တရီ တစ်ခု ရှိ/မရှိ စစ်ဆေးကြည့်ရအောင်။

php<?php
  $res = file_exists('images/');
  var_dump($res);
?>

ကုဒ်ကို run လိုက်ရင် ရလာဒ် (ဒိုင်ရက်တရီ ရှိခဲ့ရင်)။

phptrue

ဤအကြောင်းကိုလည်း ကြည့်ပါ

  • is_dir function,
    သည်လည်း ဖိုင်‌တွဲကို စစ်ဆေးပေးသည်
  • is_file function,
    သည်လည်း ဖိုင်ကို စစ်ဆေးပေးသည်
  • is_readable function,
    သည်လည်း ဖတ်၍ရ/မရ စစ်ဆေးပေးသည်
  • is_writable function,
    သည်လည်း ရေးသား၍ရ/မရ စစ်ဆေးပေးသည်