een array sorteren met een button.
ik heb een map op mijn site die ik kan bekijken met mijn script.
ik kan ook de files downloaden voor de rest niet aanpassen.
nu wil ik de bestanden eigenlijk op 2 manieren kunnen sorteren.
op naam en op de aangemaakte datum.
is dit mogelijk en hoe pas ik dat in mijn script toe?
Edit : misschien moet het iets duidelijker. het sorteren lukt wel alleen wil ik met bijvoorbeeld een button kunnen switchen tussen asort en rsort is dit mogelijk?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
// GET FILES AND PUT INTO AN ARRAY
$files = $directories = array();
$handle=opendir(dirname(__FILE__));
while (($file = readdir($handle))!==false) { $files[] = $file; }
closedir($handle);
asort($files);
// GET DIRECTORIES
foreach($files as $c => $file)
{
if(!is_dir($file)) { continue; }
if(in_array($file, $ignore_file_list)) { continue; }
if(in_array($fileExt, $ignore_ext_list)) { continue; }
echo "<div class=\"media_block\">";
echo " <div class=\"media_block_image\"><a href=\"$file\" class=\"dir\"> </a></div>";
echo " <div class=\"media_block_name\">\n";
echo " <div class=\"media_block_file\"><a href=\"$file\">$file</a></div>\n";
echo " <h6><div class=\"media_block_date\">Last modified: " . date("D. F jS, Y - h:ma", filemtime($file)) . "</div>\n</h6>";
echo " </div>\n";
echo "</div>";
unset($files[$c]);
}
// LOOP THE FILES
foreach($files as $file)
{
$fileExt = getFileExt($file);
if(in_array($file, $ignore_file_list)) { continue; }
if(in_array($fileExt, $ignore_ext_list)) { continue; }
if(is_dir($file)) { $fileExt = "dir"; }
echo "<div class=\"media_block\">";
echo " <div class=\"media_block_image\"><a href=\"$file\" class=\"$fileExt\"> </a></div>";
echo " <div class=\"media_block_name\">\n";
echo " <div class=\"media_block_file\"><a href=\"$file\">$file</a></div>\n";
echo " <h6><div class=\"media_block_date\">Size: " . format_size($file) . "<br />Last modified: " . date("D. F jS, Y - h:ma", filemtime($file)) . "</div>\n</h6>";
echo " </div>\n";
echo "</div>";
}
?>
// GET FILES AND PUT INTO AN ARRAY
$files = $directories = array();
$handle=opendir(dirname(__FILE__));
while (($file = readdir($handle))!==false) { $files[] = $file; }
closedir($handle);
asort($files);
// GET DIRECTORIES
foreach($files as $c => $file)
{
if(!is_dir($file)) { continue; }
if(in_array($file, $ignore_file_list)) { continue; }
if(in_array($fileExt, $ignore_ext_list)) { continue; }
echo "<div class=\"media_block\">";
echo " <div class=\"media_block_image\"><a href=\"$file\" class=\"dir\"> </a></div>";
echo " <div class=\"media_block_name\">\n";
echo " <div class=\"media_block_file\"><a href=\"$file\">$file</a></div>\n";
echo " <h6><div class=\"media_block_date\">Last modified: " . date("D. F jS, Y - h:ma", filemtime($file)) . "</div>\n</h6>";
echo " </div>\n";
echo "</div>";
unset($files[$c]);
}
// LOOP THE FILES
foreach($files as $file)
{
$fileExt = getFileExt($file);
if(in_array($file, $ignore_file_list)) { continue; }
if(in_array($fileExt, $ignore_ext_list)) { continue; }
if(is_dir($file)) { $fileExt = "dir"; }
echo "<div class=\"media_block\">";
echo " <div class=\"media_block_image\"><a href=\"$file\" class=\"$fileExt\"> </a></div>";
echo " <div class=\"media_block_name\">\n";
echo " <div class=\"media_block_file\"><a href=\"$file\">$file</a></div>\n";
echo " <h6><div class=\"media_block_date\">Size: " . format_size($file) . "<br />Last modified: " . date("D. F jS, Y - h:ma", filemtime($file)) . "</div>\n</h6>";
echo " </div>\n";
echo "</div>";
}
?>
Gewijzigd op 26/03/2014 20:48:59 door Marcel sauer
Er zijn nog geen reacties op dit bericht.