{"id":1580,"date":"2014-05-04T09:16:56","date_gmt":"2014-05-04T09:16:56","guid":{"rendered":"http:\/\/portfolio.arnoldbiffna.com\/?p=69"},"modified":"2025-09-24T14:35:06","modified_gmt":"2025-09-24T14:35:06","slug":"getdirectoryandfilesinfo","status":"publish","type":"post","link":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/2014\/05\/04\/getdirectoryandfilesinfo\/","title":{"rendered":"getDirectoryAndFilesInfo"},"content":{"rendered":"<p>An expanded version of the <a title=\"getDirectory\" href=\"http:\/\/www.arnoldbiffna.com\/2014\/05\/04\/getdirectory\/\">getDirectory<\/a> 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&#8217;s part of my MediaService class in AMFPHP.<\/p>\n<p>To try it out:<\/p>\n<ol>\n<li>go to\u00a0<a href=\"http:\/\/as3.actionscriptdude.com\/amfphp\/browser\/\" target=\"_blank\" rel=\"noopener\">http:\/\/as3.actionscriptdude.com\/amfphp\/browser\/<\/a><\/li>\n<li>Click on <em>MediaService<\/em><\/li>\n<li>click on <em><a title=\"Gathers filenames and file sizes within a specific directory, from the root &quot;media&quot; folder of the site\">getDirectoryAndFilesInfo<\/a><\/em><\/li>\n<li>for the\u00a0<em>dir_<\/em> parameter, type in <strong>public\/vids<\/strong><\/li>\n<li>click on\u00a0<em>Submit Query<\/em><\/li>\n<li>You should see a list of objects containing information about each video file<\/li>\n<\/ol>\n<p><a href=\"https:\/\/d3od4vl78dd97d.cloudfront.net\/blogimages\/getdirectoryandfilesinfo.gif\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/d3od4vl78dd97d.cloudfront.net\/blogimages\/getdirectoryandfilesinfo.gif\" \/><\/a><br \/>\nThis is used in the <a title=\"Flex Video Folder Browser\" href=\"http:\/\/www.arnoldbiffna.com\/2014\/05\/04\/flex-video-folder-browser\/\">Video Playlist <\/a>example.<\/p>\n<p>PHP Source:<\/p>\n<pre class=\"brush:php\">\ngetDirectoryAndFilesInfo($dir_)\n{\n  \/\/ create an array to hold directory list\n  $result = array();\n  $directory=\"..\/..\/\" . $dir_;\n  result = array();\n  \/\/ create a handler for the directory\n  $handler = opendir($directory);\n  \/\/do not allow if directory contains \"..\" SECURITY BREACH!\n  $breach = strpos($dir_,\"..\");\n  if ($breach === false\u00a0 ) {\n\n    \/\/ keep going until all files in directory have been read\n    while ($file = readdir($handler)) {\n      if ($file != '.' &amp;&amp; $file != '..')\n      {\n        $path_parts = pathinfo($file);\n        $ext=strtolower($path_parts[\"extension\"]);\n        $fObj=array();\n        $fObj[\"name\"]=$file;\n        $fObj[\"size\"]= filesize($directory . \"\/\" . $file);\n        $fObj[\"extension\"]=$ext;\n        $fObj[\"isdir\"]=is_dir($directory . \"\/\" . $file);\n\n        if ($fObj[\"isdir\"] || $ext==\"flv\" || $ext==\"jpg\" || $ext==\"mp3\" || $ext==\"png\")\n        {\n\n          $sql2=\"SELECT COUNT(*) FROM comments WHERE file= '$file'\";\n          $query2 = mysql_query($sql2);\n          $getrow2 =\u00a0 mysql_fetch_array($query2);\n          $fObj[\"commentcount\"]=$getrow2[0];\n\n          $sql=\"SELECT *\u00a0 FROM filedetails WHERE filename= '\" . $file . \"'\";\n          $query = mysql_query($sql);\n          $getrow =\u00a0 mysql_fetch_array($query);\n          $fObj[\"lookup\"] = $getrow ;\n\n          array_push($result,$fObj);\n        }\n      }\n    }\n\n    \/\/ tidy up: close the handler\n    closedir($handler);\n  }\n  return $result;\n}\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s part of my MediaService class in AMFPHP. To try it out: go to\u00a0http:\/\/as3.actionscriptdude.com\/amfphp\/browser\/ Click on MediaService click on getDirectoryAndFilesInfo for &hellip; <a href=\"https:\/\/portfolio.arnoldbiffna.com\/index.php\/2014\/05\/04\/getdirectoryandfilesinfo\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;getDirectoryAndFilesInfo&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":1884,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[12],"class_list":["post-1580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-amfphp"],"_links":{"self":[{"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/posts\/1580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/comments?post=1580"}],"version-history":[{"count":1,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/posts\/1580\/revisions"}],"predecessor-version":[{"id":1833,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/posts\/1580\/revisions\/1833"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/media\/1884"}],"wp:attachment":[{"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/media?parent=1580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/categories?post=1580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/portfolio.arnoldbiffna.com\/index.php\/wp-json\/wp\/v2\/tags?post=1580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}