Jump to content

working out file sizes xml


graham23s

Recommended Posts

Hi Guys,

 

finally got my code done for reading .xml files but when it comes to assigning the results back for the size into mb and gb i don't know what to do

 

this code:

 

     foreach($xml->{"file"} as $nfile) {
     
        $nposter = (string) trim($nfile['poster']);
        $nposter = ($nposter);
                    
        $ndate = 0 + trim($nfile['date']);
                    
        $nsubject = (string) trim($nfile['subject']);
        // To find num of segments in subject:
        $nsubjsegs = 0 + subj_seg($nsubject);
        
        // To find out if Par or not
        $npar = (stristr($nsubject, "par2")?0:1);
        
        $nsubject = ($nsubject);
                    
        $groups = array();
        foreach($nfile->groups->group as $group) {
              $groups[] = (string) trim($group);
        }
        
        $ngroups = (serialize($groups));
        
        $size = 0;
        foreach($nfile->segments->segment as $segment)
        $size += $segment['bytes'];
                          
      }

 

gives back this for the size:

 

52617506

 

can anyone tell me how to go about changing size into 1 more readable like in megabytes and gigabytes.

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/67085-working-out-file-sizes-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.