help with php, I'm confused here

User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Reporting size in B, KB, MB, etc.. in php

Post by Neo » Sun Apr 25, 2010 3:02 am

The formatBytes function you have added is very good. It switches to B, KB, MB, etc... as when the file grows. This is the most appropriate way to report a dynamically expanding file. You can use the function as below. The precision is set to 2 which will give you the result up to 2 decimal points.

Code: Select all

echo $file . ': ' . formatBytes(filesize($path."/".$file), 2) . ' </a><br/>'; 
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: help with php, I'm confused here

Post by Neo » Sun Apr 25, 2010 3:11 am

The other question is about getting the extension for each file type and proceed encoding. As said by you, the preg... isn't required. What we do here is, we first get the file extension, then replace the extension for the srt, idx, jpg, etc... and pass it to encoder. Use the following code.

Code: Select all

            if ( is_file($dir.$file) ){

                $ext = substr(strrchr($file, '.'), 0);

                if ($ext == ".avi" || $ext == ".wmv"){    // you can add more media file types to this condition
             
                   $sub_file = str_ireplace($ext, ".srt", $dir.$file);
                   $idx_file = str_ireplace($ext, ".idx", $dir.$file);
                   $thumb_file = str_ireplace($ext, ".jpg", $dir.$file);
                   $out_file = str_ireplace($ext, ".drc", $dir.$file);
                   flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
                }
                else{
                    continue;
                }
            }
 
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Tue Apr 27, 2010 1:05 am

thanks neo, i get the size part :D working i'm using now the interface to encode files and display on my wordpress :D
Post Reply

Return to “PHP & MySQL”