php get file size code example

Example 1: filesize in php

$file = '/path/to/your/file';
$filesize = filesize($file); // bytes
$filesize = round($filesize / 1024 / 1024, 1); // megabytes with 1 digit
 
echo "The size of your file is $filesize MB.";

Example 2: php get size of file

$fileSizeInBytes=filesize("/path/to/myfile.txt");

Example 3: php get filetype

<?php
echo filetype('/etc/passwd');  // file
echo filetype('/etc/');        // dir
?>

Example 4: filesize in php

$file = '/path/to/your/file';
$filesize = filesize($file);
 
echo "The size of your file is $filesize bytes.";

Example 5: get file size in php

$img = get_headers("file URL", 1);
echo $img["Content-Length"];

Tags:

Php Example