linein designs

25 Apr, 2007

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

Similar Posts:

4 Comments »

Comment by Eric

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.

Comment by john

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

 
 
 
Comment by Abeon

A very simple and effective solution, thanks for sharing it!

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post



Please Support Our Friends

Send emails with ease on this SMTP server by JangoSmtp.com.

Banner

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.