Calculate download time

Discussion in 'PHP' started by Toopac, Feb 18, 2009.

  1. #1
    I have a script that has the file size as a value say for instance: $filesize

    I would like to display the download times for various connections by using the value $filesize.

    Do you have a snippet of code for this etc?

    Thanks in advance.
     
    Toopac, Feb 18, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <?php
    
    function downloadTime( $size_of_file_in_bytes, $download_kilobytes_per_second )
    {
        $seconds = $size_of_file_in_bytes / ( $download_kilobytes_per_second * 1024 );
        $minutes = floor( $seconds / 60 );
        $seconds = $seconds % 60;
        return array( 'minutes' => $minutes, 'seconds' => $seconds );
    }
    
    list( $minutes, $seconds ) = array_values( downloadTime(10489999, 2048) );
    echo $minutes . ' minutes ' . $seconds . ' seconds.';
    PHP:
     
    Danltn, Feb 18, 2009 IP