Web Analytics Made Easy -
StatCounter How to show server's free disk space - CodingForum

Announcement

Collapse
No announcement yet.

How to show server's free disk space

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to show server's free disk space

    Hey!

    So imagine this scenario:
    You have a server which aint in your complete control. You have some space there EG 500MB.
    You know that depending on the activity there will be more or less space at times.

    How can you show on that web page how much space you have left of that
    500MB to the private audience?

    I belive this can be done in PHP in some way, I just couldnt google my way
    to any answers so Im trying my luck if any of you have ever thought of such
    thing

    Thanks in advance.

  • #2
    if its a linux server try

    PHP Code:
    <?php
    echo exec('df');
    ?>
    or

    PHP Code:
    <?php
    echo shell_exec('df');
    ?>
    Not sure about windows server just find out the dos command for it.
    You can not say you know how to do something, until you can teach it to someone else.

    Comment


    • #3
      Or even better try

      PHP Code:
      <?php
      // On linux/ unix:
      $df disk_free_space("/"); // $df contains the number of bytes available on "/"
      echo $df;

      // On Windows:
      echo disk_free_space("C:");
      ?>
      You can not say you know how to do something, until you can teach it to someone else.

      Comment


      • #4
        Or even better:
        PHP Code:
        echo disk_free_space(realpath('/')); // works on windows and linux 
        The comments for the complement function to this one, disk_total_space() show how to convert bytes to kilobyte, megabytes, gigabytes, etc. You can find similar functions all over the place, too.

        Comment


        • #5
          Thanks both of you for taking the time
          Alright so my server has exec disabled, but its good to know it.
          The other one works perfectly, thanks for that!

          Comment

          Working...
          X