PHPFront

Home > PHP > Get the size of a file
The PHP website created by its users!



Get the size of a file


Author
DescriptionReturns the size of any file using filesize()
RatingThis script has been rated 2/5 (26 votes)

PHP Code


<?php

$file  
'myfilename.gif';

echo 
filesize($file);


?>



Rate it: Print Print

Comments


jumbosheep / 28 Nov 05

do you have to open the file in read mode first though?
jumbosheep / 28 Nov 05

i dont understand why this wouldnt just make the variable have a value of "myfilename.gif" , by putting single quotes around it, does it make it special?
mkeefe / 30 Nov 05

The variable "$file" is being filled with the quoted string. You would use this in a completed project more because it allows you to change things later down the road.

The "filesize" function does not require you to open the file to check the size. A good use for this is to check for filesize before you open it to ensure the file is intact and won't crash your system.

Matt
Jesse / 3 Dec 05

This is pretty cool this may come in handy thanks so much. What version of PHP is this for, I have 5.0 or so locally, but my host is 4.1.3 (I think) and some things I read in my PHP 5 book wont apply to my host. :(
jumbosheep / 7 Dec 05

it'll work in 4 easily
whats the difference between single and double quote in php?
Admin / 5 Jan 06

PHP will parse code in double quotes, but not single quotes. Using single quotes for echo'ing will make your php code faster, though not really noticable.

Name
Website
Your comment