PHP and Dreamy Audio

I’ve been working with my audio and video files from audioblogs. I’m mostly working on getting a script setup to list all files within the directory. This is simple enough, but I’m also trying to parse the meta data out of those files as well such as the title, comments, artist, play time, etcetra. You can temporarily see how far I have gotten so far over at my Dreamy Audio testing site. In the end, I’ll be able to simply upload a new MP3 file into the directory and everything else will be taken care of as long as I’ve properly edited the MP3’s meta data before doing so.

Most of the parsing is taken care of through an open-source library that I found on the internet. I’ll need to work on refining the RSS feed to sort in the same way. Next is to apply the same technique to my Flash Video files (FLV). I promised I would say something about that soon. I’ll try and get something posted before the end of the week.

For now, anyone playing with PHP and listing file sizes might find this small piece of code useful. It converts the bytes to KB, MB, GB, TB, or PB to make the file sizes more easier to read.

171 function calcBytes($bytes)
172 {
173 $unit = ‘bytes’;
174 while($bytes > 768)
175 {
176 switch($unit)
177 {
178 case ‘bytes’: $unit = ‘KB’;break;
179 case ‘KB’: $unit = ‘MB’;break;
180 case ‘MB’: $unit = ‘GB’;break;
181 case ‘GB’: $unit = ‘TB’;break;
182 case ‘TB’: $unit = ‘PB’;break;
183 default: continue 2;
184 }
185 $bytes = $bytes / 1024;
186 }
187 return round($bytes, 1).‘ ‘.$unit;
188 }

Leave a Reply