Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: PHP is not finding correct dir size (%)  (Read 4346 times)

0 Members and 1 Guest are viewing this topic.

Bannana97

    Topic Starter


    Intermediate
  • Owner of HerbertsWorld Corporation
    PHP is not finding correct dir size (%)
    « on: June 12, 2009, 01:58:34 PM »
    I am trying to make this php code echo the % of space used. (%/100)

    It doesn't work.

    Code: [Select]
    function roundsize($size){
        $i=0;
        $iec = array("B", "Kb", "Mb", "Gb", "Tb");
        while (($size/1024)>1) {
            $size=$size/1024;
            $i++;}
        return(round($size,1)." ".$iec[$i]);}
    $user = $_COOKIE['usernamm'];
    $web = file_get_contents("system/web_$user.txt");
    $space = disk_total_space("$web/");
    $space = $space;
    $space = roundsize($space);
    echo "$space%";
    Thanks
    Bannana97

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: PHP is not finding correct dir size (%)
    « Reply #1 on: June 12, 2009, 02:09:11 PM »
    I think it might be because of $space%.

    Try echo "{$space}%";

    Bannana97

      Topic Starter


      Intermediate
    • Owner of HerbertsWorld Corporation
      Re: PHP is not finding correct dir size (%)
      « Reply #2 on: June 12, 2009, 02:36:59 PM »
      No, I just don't know how to actully "get" the  % from 100..
      Any clue?
      Thanks
      Bannana97

      Bannana97

        Topic Starter


        Intermediate
      • Owner of HerbertsWorld Corporation
        Re: PHP is not finding correct dir size (%)
        « Reply #3 on: June 12, 2009, 02:39:01 PM »
        Output (Bites)



        2141653.08%


        It needs to be  $space/100 into a %.
        Thanks
        Bannana97

        Rob Pomeroy



          Prodigy

        • Systems Architect
        • Thanked: 124
          • Me
        • Experience: Expert
        • OS: Other
        Re: PHP is not finding correct dir size (%)
        « Reply #4 on: June 12, 2009, 03:20:47 PM »
        Is this a maths question?!
        Only able to visit the forums sporadically, sorry.

        Geek & Dummy - honest news, reviews and howtos

        Bannana97

          Topic Starter


          Intermediate
        • Owner of HerbertsWorld Corporation
          Re: PHP is not finding correct dir size (%)
          « Reply #5 on: June 12, 2009, 03:31:28 PM »
          I don't know how to get the file size in php and make it a percentage...
          Thanks
          Bannana97

          Bannana97

            Topic Starter


            Intermediate
          • Owner of HerbertsWorld Corporation
            Re: PHP is not finding correct dir size (%)
            « Reply #6 on: June 12, 2009, 03:31:42 PM »
            I mean directory size XD
            Thanks
            Bannana97

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: PHP is not finding correct dir size (%)
            « Reply #7 on: June 12, 2009, 08:51:05 PM »
            divide the size of the item your acquiring the percentage for by the total size.

            and then if you want to get the space not used by that item, subtract the resulting number from 1.

            For example if you have a 5MB file on a 1GB drive, that's 5/1024=0.48828125%.
            I was trying to dereference Null Pointers before it was cool.

            Bannana97

              Topic Starter


              Intermediate
            • Owner of HerbertsWorld Corporation
              Re: PHP is not finding correct dir size (%)
              « Reply #8 on: June 13, 2009, 09:05:18 AM »
              Okay. So, this will work ?

              Code: [Select]

              $space = disk_total_space("$web/");
              $space = $space / disk_free_space("$web/");
              echo $space;

              Thanks
              Bannana97

              Rob Pomeroy



                Prodigy

              • Systems Architect
              • Thanked: 124
                • Me
              • Experience: Expert
              • OS: Other
              Re: PHP is not finding correct dir size (%)
              « Reply #9 on: June 13, 2009, 01:41:56 PM »
              Only able to visit the forums sporadically, sorry.

              Geek & Dummy - honest news, reviews and howtos

              Bannana97

                Topic Starter


                Intermediate
              • Owner of HerbertsWorld Corporation
                Re: PHP is not finding correct dir size (%)
                « Reply #10 on: June 14, 2009, 09:33:57 AM »
                .. Yes. .
                Thanks
                Bannana97

                Rob Pomeroy



                  Prodigy

                • Systems Architect
                • Thanked: 124
                  • Me
                • Experience: Expert
                • OS: Other
                Re: PHP is not finding correct dir size (%)
                « Reply #11 on: June 15, 2009, 07:59:18 AM »
                Sorry, we don't have a maths forum  ;)
                Only able to visit the forums sporadically, sorry.

                Geek & Dummy - honest news, reviews and howtos

                kpac

                • Web moderator
                • Moderator


                • Hacker

                • kpac®
                • Thanked: 184
                  • Yes
                  • Yes
                  • Yes
                • Certifications: List
                • Computer: Specs
                • Experience: Expert
                • OS: Windows 7
                Re: PHP is not finding correct dir size (%)
                « Reply #12 on: June 15, 2009, 10:03:16 AM »
                Rob, Banana97 obviously doesn't know the code or the function in PHP to do what he wants to, so he has asked you how to do it - not keep repeating the same thing over.

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: PHP is not finding correct dir size (%)
                « Reply #13 on: June 15, 2009, 03:17:42 PM »
                looks to me, like he knew all the functions he needed.

                Just didn't know the percentage formula.
                I was trying to dereference Null Pointers before it was cool.