php - How can i sort this list by "date modified"? -
i have been trying mp3 player order songs " date modified" can't seem work properly. there way can output results " date modified"? can me out this?
/* reads mp3's local directory, returns array of uri's */ function grab_local_folder_mp3s( $folder ) { $items = array_multisort( array_map( 'filemtime', $items ), sort_numeric, sort_desc, $items ); if ( ($lp = strpos($folder, $this->rooturl)) || preg_match("!^/!", $folder) ) { if ( $lp !== false ) { $fp = str_replace($this->rooturl, "", $folder); $fp = str_replace("www.", "", $fp); $fp = str_replace("http://", "", $fp); $fp = str_replace("https://", "", $fp); } else { $fp = $folder; } $path = $_server['document_root'] . $fp; if ($handle = @opendir($path)) { $j=0; while (false !== ($file = readdir($handle))) { if ( $file != '.' && $file != '..' && filetype($path.'/'.$file) == 'file' && preg_match("!\.mp3$!i", $file) ) { $items[$j++] = $file; } } closedir($handle); if ( ($c = count($items)) > 0 ) { asort($items); if ( $this->folder_order != "asc" ) { $items = array_reverse($items, true); } $fp = preg_replace( "!/+$!", "", $fp ); foreach ( $items $i => $mp3 ) { $items[$i] = "http://" . $_server['http_host'] . $fp . "/" . $mp3; } } $this->dbug['str'] .= "\nread folder - done, " . $c . "mp3(s) in folder http://" . $_server['http_host'] . $fp; return $items; //the tracks array } else { $this->dbug['str'] .= "\nread folder - couldn't open local folder, check path/permissions http://" . $_server['http_host'] . $fp; return true; } } else { $this->dbug['str'] .= "\nread folder - path remote or unreadable." . $fp; return false; } }
unless have special powers, $items
variable remains undefined:
function grab_local_folder_mp3s( $folder ) { $items = array_multisort( array_map( 'filemtime', $items ), sort_numeric, sort_desc, $items );
and beginning of function. maybe it's worth think how split code across more 1 function? rule of saying is: 6 lines in function. if gets longer, start think how move code out of it. try it, works wonder.
and development: enable error reporting highest level , trace error log. php tells such mistakes , know quite fast then. keep php updated best error messages available.