File tree Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Expand file tree Collapse file tree 2 files changed +29
-13
lines changed Original file line number Diff line number Diff line change 66 *
77 * @return string
88 */
9+
910$ function_size_conversion = function ($ size ) {
1011 $ units = [
1112 'B ' ,
100101};
101102
102103$ function_order_paths = function ($ paths ) {
103- $ order_by = isset ($ _GET ['order_by ' ]) ? $ _GET ['order_by ' ] : 'filename ' ;
104- $ types = [];
105- $ keys = [];
106- $ i = 0 ;
107- foreach ($ paths as $ path )
104+ sort ($ paths );
105+
106+ if (isset ($ _GET ['order_by ' ]) && in_array ($ _GET ['order_by ' ], [
107+ 'type ' ,
108+ 'filename ' ,
109+ 'size ' ,
110+ 'owner ' ,
111+ 'group ' ,
112+ 'perms ' ,
113+ 'mTime ' ,
114+ ]))
108115 {
109- $ keys [$ path ['type ' ]][$ path [$ order_by ]] = $ path ;
110- sort ($ keys [$ path ['type ' ]]);
116+ usort ($ paths , function ($ path1 , $ path2 ) {
117+ $ order_by = $ _GET ['order_by ' ];
118+
119+ $ path1 ['mTime ' ] = strtotime ($ path1 ['mTime ' ]);
120+ $ path2 ['mTime ' ] = strtotime ($ path2 ['mTime ' ]);
121+
122+ if ($ path1 [$ order_by ] === $ path2 [$ order_by ])
123+ {
124+ return 0 ;
125+ }
126+
127+ return $ path1 [$ order_by ] < $ path2 [$ order_by ] ? -1 : 1 ;
128+ });
111129 }
112130
113- foreach ( $ keys as $ k => $ v )
131+ if ( isset ( $ _GET [ ' order ' ]) && $ _GET [ ' order ' ] === ' asc ' )
114132 {
115- //$types[$k] ;
133+ $ paths = array_reverse ( $ paths ) ;
116134 }
117135
118- var_dump ($ keys );
119- exit ;
120136 return $ paths ;
121137};
Original file line number Diff line number Diff line change 125125 'href ' => $ function_path_href ($ SplFileInfo ),
126126 ];
127127}
128- sort ( $ paths );
129- // $paths = $function_order_paths($paths);
128+
129+ $ paths = $ function_order_paths ($ paths );
130130
131131$ title = 'Index of ' . (empty ($ relative_path ) ? '/ ' : $ relative_path );
132132
You can’t perform that action at this time.
0 commit comments