filesize Fonksiyonu

filesize fonksiyonu, dosyanın boyutunu bayt cinsinden döndürür. Fonksiyon, parametre olarak dosyanın yolunu alır. Eğer dosya mevcut değilse, fonksiyon false döndürür ve bir uyarı oluşturur.

Sözdizimi

phpfilesize(dosyaadı);

Örnek

'test.txt' dosyasının boyutunu alalım:

php<?php
  $res = filesize('test.txt');
  echo $res;
?>

Kodun çalışma sonucu (örneğin):

php1024

Örnek

Dosya boyutunu almadan önce dosyanın varlığını kontrol edelim:

php<?php
  $filename = 'test.txt';
  
  if (file_exists($filename)) {
    $res = filesize($filename);
    echo "Dosya boyutu: " . $res . " bayt";
  } else {
    echo "Dosya bulunamadı";
  }
?>

Kodun çalışma sonucu:

php'Dosya boyutu: 1024 bayt'

Örnek

Dosya boyutunu alıp kilobayta dönüştürelim:

php<?php
  $res = filesize('test.txt') / 1024;
  echo round($res, 2) . " KB";
?>

Kodun çalışma sonucu:

php'1.00 KB'

Ayrıca Bakınız