Location: PHPKode > projects > Easy Music Box > lib/class.browse.inc
<?php
/*
 * @package    Easy MusicBox
 * @author     Kevin Pentiah <hide@address.com>
 * @copyright  2006 3scriptz
 * @license    PHP License 
 * @version    Release: 1.0.0
 * @link       http://www.3scriptz.com
 * @since      Class available since Release 1.0.0
 * @desc	browser files and folders with pagination
 */

//browse files
class browse extends file_details {
      var $folder;
      var $file;
      var $files = array();
      var $handle;
      var $music_files = array ("mp3", "wma");
      var $ext;
      var $path;
      var $fullpath;
      var $total;


      //check if folder
      function browse($folder) {
            if (!is_dir($folder)) {
              echo "$folder is an Invalid directory";
              exit();
            }
      }

      //get all files from folder
      function list_all($folder) {
            if ($this->handle = opendir($folder)) {
               while (false !== ($this->file = readdir($this->handle))) {
                      array_push($this->files,$this->file);
               }
               return $this->files;
               closedir($this->handle);
            }
      }

      //check if file is a folder
      function folder_check($fullfile,$file) {
            if (is_dir($fullfile) && $file!='.' && $file!='..') {
                return true;
            }
            else {
                return false;
            }
      }

      //check if is a music file
      function music_check($file) {
            $this->ext = substr (strrchr ($file, "."), 1);
            if (array_search ($this->ext, $this->music_files) !== FALSE)
                return true;
            else
                return false;
      }

      //count of music files
      function music_count($path) {
            $this->files = array();
            if ($this->handle = opendir($path)) {
               while (false !== ($this->file = readdir($this->handle))) {
               $fullfile = "$path{$this->file}";
                             if ($this->music_check($this->file) && !is_dir($fullfile)) {
                                     array_push($this->files,$this->file);
                              }
               }
               return sizeof($this->files);
               closedir($this->handle);
            }
      }
      //recursive list
      function recursive($path) {
               $file_array = array();
               $browse = new browse ($path);
               $all_files = $browse->list_all($path);
               foreach ($all_files as $this->file) {
                         if ($this->file != "." && $this->file != "..") {
                              $this->path = "$path{$this->file}/";
                              $this->fullpath = "$path{$this->file}";
                              if (is_dir($this->path)) {
                                 $this->list_all($this->path);
                                 $folder_array = $this->recursive($this->path,$file_array);
                                 if(is_array($folder_array)) {
                                    $file_array = array_merge($file_array, $folder_array);
                                 }
                              }
                              else {
                                    if ($browse->music_check($this->fullpath)) {
                                          //array_push($file_array,$this->fullpath);
                                          $date = filemtime($this->fullpath);
                                          $file_array[] = array($this->path_name($this->fullpath), $date, $this->song_name($this->fullpath));
                                    }
                              }
                         }
               }
               return $file_array;
      }
      //paginate
      function paginate_array($arrayin,$limit,$array_num,$page,$type) {
            $this->count = sizeof($arrayin);
            $next_page = $this->total/$limit + 1;
            $this->total = $array_num + $limit;
            if ($this->total >= $this->count)
                $this->total = $this->count;

            $total_pages = $this->count/$limit;
            echo '<form style="text-align: center" method="post" id="3z_id" name="3z_name" action="" onsubmit="doSubmit(this)"><p align="center"><br />';

            for ($i = $array_num; $i<$this->total; $i++) {
               echo '<input type="checkbox" name="pick[]" value="upload'.$arrayin[$i][0].'" />'.$arrayin[$i][2].'<br />';
            }
            if ($this->total > $limit) {
                 echo '<a href="?act='.$type.'&p='.($page-1).'"> Previous  </a>';
            }
            for ($i = 1; $i<$total_pages+1; $i++) {
                 echo '<a href="?act='.$type.'&p='.($i).'"> '.$i.'  </a>';
            }
            if ($this->total < $this->count) {
                 echo '<a href="?act='.$type.'&p='.($page+1).'">  Next>></a>';
            }

          ?>
          <br>
          <input type=button value="Select All" onClick="SelectAll()">
          <input type="submit" value="Play" onclick="popupMode=true" />
          <input type="submit" value="Add to playlist" onclick="popupMode=false" />
          <input type="reset" value="Reset" />
          </p></form><br>
          <?

      }
}

?>
Return current item: Easy Music Box