getDirectoryAndFilesInfo

An expanded version of the getDirectory call, but also uses the file name as a key to more information in the database. This is useful for describing media such as video, sound, and pictures. It’s part of my MediaService class in AMFPHP.

To try it out:

  1. go to http://as3.actionscriptdude.com/amfphp/browser/
  2. Click on MediaService
  3. click on getDirectoryAndFilesInfo
  4. for the dir_ parameter, type in public/vids
  5. click on Submit Query
  6. You should see a list of objects containing information about each video file


This is used in the Video Playlist example.

PHP Source:

getDirectoryAndFilesInfo($dir_)
{
  // create an array to hold directory list
  $result = array();
  $directory="../../" . $dir_;
  result = array();
  // create a handler for the directory
  $handler = opendir($directory);
  //do not allow if directory contains ".." SECURITY BREACH!
  $breach = strpos($dir_,"..");
  if ($breach === false  ) {

    // keep going until all files in directory have been read
    while ($file = readdir($handler)) {
      if ($file != '.' && $file != '..')
      {
        $path_parts = pathinfo($file);
        $ext=strtolower($path_parts["extension"]);
        $fObj=array();
        $fObj["name"]=$file;
        $fObj["size"]= filesize($directory . "/" . $file);
        $fObj["extension"]=$ext;
        $fObj["isdir"]=is_dir($directory . "/" . $file);

        if ($fObj["isdir"] || $ext=="flv" || $ext=="jpg" || $ext=="mp3" || $ext=="png")
        {

          $sql2="SELECT COUNT(*) FROM comments WHERE file= '$file'";
          $query2 = mysql_query($sql2);
          $getrow2 =  mysql_fetch_array($query2);
          $fObj["commentcount"]=$getrow2[0];

          $sql="SELECT *  FROM filedetails WHERE filename= '" . $file . "'";
          $query = mysql_query($sql);
          $getrow =  mysql_fetch_array($query);
          $fObj["lookup"] = $getrow ;

          array_push($result,$fObj);
        }
      }
    }

    // tidy up: close the handler
    closedir($handler);
  }
  return $result;
}

Leave a Reply

Your email address will not be published. Required fields are marked *