Page 1 of 1
php's disk_total_space always return free space
Posted: Thu Jul 19, 2012 7:14 am
by saar62097
i know little php and i am trying to determine available space on the server. the server is a shared hosting type
this code returns the same size for free and total.
folder "media" has many files in it.
seems like the total returns the free space also since if i upload files to this folder, this script returns a new size (but same size for total and free)
anyone know why?
Code: Select all
?php
$fs ="media";
$df = disk_free_space($fs);
echo "space free is:";
echo $df;
$dt = disk_total_space($fs);
echo "space total is:";
echo $dt;
?>
Re: php's disk_total_space always return free space
Posted: Thu Jul 19, 2012 4:15 pm
by mixa2000
That's because "media" is a folder and not a hard-drive.
I guess you have a "localhost" server, like on your own computer, try this code and see how it works,
but it cannot check for a folder, because a folder doesn't has "limits", the hard-drive does.
Code: Select all
<?php
// fs is the drive, if you have this file like in a folder, which is
// in a folder, which is in a folder, etc. then you might need
// more of those ../ in the $fs
$fs ="../../../../../";
$df = disk_free_space($fs) / 1024 / 1024 / 1024;
echo "Free space is : " . $df . " GBs" . "<br>";
$dt = disk_total_space($fs) / 1024 / 1024 / 1024;
echo "Total space is : " . $dt . " GBs";
?>
If you have any questions regarding this, feel free to ask here.

Re: php's disk_total_space always return free space
Posted: Thu Jul 19, 2012 4:36 pm
by mixa2000
By the way, there are two more things I just learned, if you put this script in the "shared hosting type" server,
it will not work, because you do not have access to that drive.
And another thing is that you can get the proper directory for it and get results,
but the results for me are like; free space = 45 GBs, and total = 950 GBs, but that's not
what you are looking for, am I right?
I see you are trying to know how much free space "you" have, and out of how much they give you,
but I guess you can't really find that out on a free hosting server, through a php script.

Re: php's disk_total_space always return free space
Posted: Sun Aug 12, 2012 2:23 am
by saar62097
thanx mixa2000
this script works well in another shared hosting server, so the issue isn't about the server being a shared type but about something in the server configuration
sorry for the late response