Mappen op alfabetische volgorde
Pagina: « vorige 1 2 3 volgende »
We zijn lekker bezig, maar ik zit eigenlijk nog wel met een probleem.
Is het mogelijk om asort($file); te gebruiken in dit stukje script?
Quote:
else{
if ($handle = opendir('media/fotos/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
if ($handle = opendir('media/fotos/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
Zou iemand uit kunnen leggen hoe ik dit kan doen?
Robin Krijger
Toevoeging op 25/09/2011 18:33:09:
Ik zou hem graag op datum willen
Hier zou het ook mee kunnen toch filemtime?
Jaa sorry op datum van de map moet hij gesorteerd worden.
Is dat ook mogelijk? http://nl3.php.net/filemtime
Robin Krijger
met de functie usort kun je zelf een sorteer-functie maken, die eventueel op filemtime checked.
maak van een $filelist een 2 dimensionale array
$files[] = [$time, $file];
Ik heb hiervoor een grote fout gemaakt, het moest inderdaad op datum.
Sorry voor de mensen op dit forum.
Beste Jacco,
Hoe zou ik die moeten inplanten?
usort($file, "file");
foreach ($file as $key => $value) {
echo "$key: $value\n";
ofz
Heel erg bedankt.
Toevoeging op 25/09/2011 19:14:29:
Ger,
Komt hij er dan zo uit te zien?
else{
if ($handle = opendir('media/fotos/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[] = [$time, $file];
}
}
asort($files)
foreach ($files as $file) {
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
Groeten Robin Krijger
je moet $file bij de echo's veranderen in $file[1]
PS.
Graag in het vervolg je code in codetags zetten ('['code']' '['/code']'
Gewijzigd op 25/09/2011 19:23:04 door Ger van Steenderen
Quote:
else{
if ($handle = opendir('media/fotos/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[] = [$time, $file];
}
}
asort($files)
foreach ($files as $file[1]) {
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
if ($handle = opendir('media/fotos/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$files[] = [$time, $file];
}
}
asort($files)
foreach ($files as $file[1]) {
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
Op deze manier zou hij het moeten doen?
Quote:
else{
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
[code] en [/code] tags
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
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
else{
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
Toevoeging op 25/09/2011 20:23:03:
Zou het op deze manier lukken?
Robin Krijger
Code (php)
1
echo "<div class=\"font\"><a href=\"?map=$file\" class=\"album-link\" TARGET=\"_top\">$file\n</a></div>";
zoals eerder gezegd moet $file vervangen worden door $file[1]
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
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
else{
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file[1]\" class=\"album-link\" TARGET=\"_top\">$file[1]\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file[1]\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file[1]\" class=\"album-link\" TARGET=\"_top\">$file[1]\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file[1]\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
zo bedoelt u?
proberen maar zou ik zeggen
Er zit waarschijnlijk nog een heel klein foutje in dan:$
Robin Krijger op 25/09/2011 20:32:44:
Parse error: syntax error, unexpected ';' in line
... in line ......... welke?
Santhe ik zag dat je er wel eens meer mee bezig was,
http://www.phphulp.nl/php/forum/topic/directory-uitlezen-en-sorteren-op-datum-aanmaak-bestanden/67371/
Misschien lukt het op deze manier.
ik denk in regel 6, daar ontbreekt een haakje
Maar geeft nog een fout melding.
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
function showfiles($map = "./", $return = array()){
if(@$dir = opendir($map)){
while (false !== ($file = readdir($dir))){
if ($file != "." && $file != ".."){
$return[] = $map . $file;
}
}
}
@closedir($dir);
return $return;
}
if(isset($_GET['map'])){
$return2 = showfiles('media/fotos/'.$_GET['map'].'/');
echo '
<div id="top_content"></div>
<div id="middle_content">
<div id="content">
<div id="page-wrap">
<H1>'.$_GET['map'].'</H1><br/> <center>
<div class="gallery clearfix">
';
//bugfix
//echo '<pre>';
//print_r($return2);
//echo '</pre>';
for($i = 0; $i < count($return2);$i++){
$name = explode("/", $return2[$i]);
if($name[3] != 'thumb'){
$dest = $name[0].'/'.$name[1].'/'.$name[2].'/thumb/'.$name[3];
$name = explode(".", $name[2]);
$empty = false;
echo '<div id="fotobook_border"><a href="'.$return2[$i].'" class="mustang-gallery" rel="prettyPhoto[gallery1]" title="'.$name[0].'"><img src="'.$dest.'" border="0" width="100" height="100" alt="'.$name[0].'" /></a></div>
';
}
}
if(!isset($empty)){
echo '<div class="font">Dit album is nog leeg.</div>';
}
echo '</div></div>
<div class="clear"></div><div id="lid_worden"><a href="/jaz/#sectionFotoalbum">Ga terug</a></div>
</div> </div>
<div id="bottom_content"></div>
';
}
else{
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file[1]\" class=\"album-link\" TARGET=\"_top\">$file[1]\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file[1]\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>
function showfiles($map = "./", $return = array()){
if(@$dir = opendir($map)){
while (false !== ($file = readdir($dir))){
if ($file != "." && $file != ".."){
$return[] = $map . $file;
}
}
}
@closedir($dir);
return $return;
}
if(isset($_GET['map'])){
$return2 = showfiles('media/fotos/'.$_GET['map'].'/');
echo '
<div id="top_content"></div>
<div id="middle_content">
<div id="content">
<div id="page-wrap">
<H1>'.$_GET['map'].'</H1><br/> <center>
<div class="gallery clearfix">
';
//bugfix
//echo '<pre>';
//print_r($return2);
//echo '</pre>';
for($i = 0; $i < count($return2);$i++){
$name = explode("/", $return2[$i]);
if($name[3] != 'thumb'){
$dest = $name[0].'/'.$name[1].'/'.$name[2].'/thumb/'.$name[3];
$name = explode(".", $name[2]);
$empty = false;
echo '<div id="fotobook_border"><a href="'.$return2[$i].'" class="mustang-gallery" rel="prettyPhoto[gallery1]" title="'.$name[0].'"><img src="'.$dest.'" border="0" width="100" height="100" alt="'.$name[0].'" /></a></div>
';
}
}
if(!isset($empty)){
echo '<div class="font">Dit album is nog leeg.</div>';
}
echo '</div></div>
<div class="clear"></div><div id="lid_worden"><a href="/jaz/#sectionFotoalbum">Ga terug</a></div>
</div> </div>
<div id="bottom_content"></div>
';
}
else{
if ($handle = opendir('media/fotos/')) {
$files = array();
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filetime = date('d-m-Y H:i:s', filemtime($file);
$files[] = $filetime . '||' . $file;
}
}
asort($files)
foreach ($files as $data) {
$file = explode('||', $data);
echo '<table border="0">';
$kleur2 = "<tr class='odd'>";
if(isset($kleur)){
echo $kleur;
unset($kleur);
}
else{
$kleur = '<tr>';
echo $kleur2;
}
echo '<td VALIGN="top" ALIGN="left" BORDER="0">';
echo "<div class=\"font\"><a href=\"?map=$file[1]\" class=\"album-link\" TARGET=\"_top\">$file[1]\n</a></div>";
echo "</td><td VALIGN=\"top\" ALIGN=\"right\"><a href=\"?map=$file[1]\" TARGET=\"_top\"/><img alt=\"Bekijk\" border=\"0\" value=\"Bekijk\" src=\"images/view.png\" >
</a></td></tr>";
} echo '</table>';
}
}
closedir($handle);
}
?>