Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Filesize for multiple files

Posted on 2011-09-09
5
Medium Priority
?
223 Views
Last Modified: 2012-08-13
Hi,

I need simple script to check size of few files, my variables are $f1, $f2, $f3, $f4, how to count total size of those files? Obviously I need to use filesize function, but how?

Thanks for any help.
0
Comment
Question by:Zado
5 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 36509269
use sum of filesize(filename) function
http://php.net/manual/en/function.filesize.php
0
 
LVL 7

Expert Comment

by:boon86
ID: 36509291
try this:
<?php
$filename1 = 'somefile1.txt';
$filename2 = 'somefile2.txt';
$filename3 = 'somefile3.txt';
$filename4 = 'somefile4.txt';

$f1 = filesize($filename1) . 'bytes';
$f2 = filesize($filename2) . 'bytes';
$f3 = filesize($filename3) . 'bytes';
$f4 = filesize($filename4) . 'bytes';

?>

hope that help
0
 
LVL 8

Author Comment

by:Zado
ID: 36509518
I found solution:

$total= (filesize($f8))+(filesize($f8b))+(filesize($f8c))+(filesize($f8d));

Open in new window

I tried this earlier, but I made mistake with round function, I've done this:
$round = round((filesize($inattsize)/1024/1024), 2)."MB"; instead this:
$round = round(($inattsize/1024/1024), 2)."MB";

Open in new window


Thanks for your help.
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 1000 total points
ID: 36509528
some thing like this,

<?php
$f1 = filesize("test1.txt");
$f2 = filesize("test2.txt");
$f3 = filesize("test3.txt");
$f4 = filesize("test4.txt");

$tot = $f1+$f2+$f3$f4;

echo "Total Size = ".$tot;

?>

Open in new window

0
 
LVL 8

Author Comment

by:Zado
ID: 36509543
Thanks.

Correction for my last comment:
There should be $total instead $inattsize;
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question