Apr
25
PHP File Last Modified and Filesize (bytes to KB/MB)
Posted by john in php, programing

Here’s a quick snip of code to help you easily manage your files by finding out the time the file was created or modified and also the time of the file.

$file = 'image.jpg';

// FILE TIME
$filetime = filemtime($file); // displays in Seconds since the Unix Epoch
echo date("M j, Y", $filetime); // would display the file creation/modified date as Feb 3, 2007

// FILE SIZES
$filesize = filesize($file); // displays in bytes
$file_kb = round(($file / 1024), 2); // bytes to KB
$file_mb = round(($file / 1048576), 2); // bytes to MB
$file_gb = round(($file / 1073741824), 2); // bytes to GB
// PHP does funny thing for files larger than 2GB

3 Responses to “PHP File Last Modified and Filesize (bytes to KB/MB)”

Eric Says:

Exactly what I was looking for. Just change the comment for the second line to “// bytes to MB” instead of KB. It’s a little misleading.

[Reply]

john reply on March 2nd, 2008:

Glad it could help. Thanks for the correction - it’s been fixed.

[Reply]

laptop satış Says:

ı like this blog . . .

[Reply]

Leave a Reply