Ownmen Posted December 10, 2009 Report Share Posted December 10, 2009 Sveiki! Esmu sastapies ar problēmu. No direktorijas izvelkot failus, vajag, lai tie tiktu sakārtoti pēc pievienošanas laika un tad secīgi ievadīti tabulā, bet rokoties internetā īsto līdzekli neatradu. Ceru uz Jūsu palīdzību! $bilde = array(); $i = 0; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { $i++; $bilde[$i] = $file; } } closedir($dh); Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted December 10, 2009 Report Share Posted December 10, 2009 Pec atslēgas vārdiem "php directory sort date" atradu šo: http://www.computing.net/answers/webdevel/php-sort-directory-contents-by-date/3483.html Quote Link to comment Share on other sites More sharing options...
briedis Posted December 10, 2009 Report Share Posted December 10, 2009 Nezinu speciālu metodi, bet var dabūt laiku, kad pēdējo reizi modificēts. Laiks ir unixtimestamp formātā. Vari salikt masīvā faila nosaukumus, un kā indeksus likt modificēšanas datumus. Un tad veikt kārtošanu pēc indeksiem. (funkcija ksort()) Tā es iztēlojos :) Gan jau, ka ir vienkāršāks veids kā to izdarīt... Just google.. Quote Link to comment Share on other sites More sharing options...
Ownmen Posted December 11, 2009 Author Report Share Posted December 11, 2009 $bytime = array(); if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { $modtime = filemtime($file); $bytime[$modtime] = $file; } } closedir($dh); } ksort($bytime); foreach($bytime as $time) { echo $time."<br />"; } Izvada tikai pēdējo bildes nosaukumu. Arī pirms ksort() izvada to pašu. Vai es neprotu datus ielikt tabulā? :/ Quote Link to comment Share on other sites More sharing options...
Val Posted December 11, 2009 Report Share Posted December 11, 2009 Tas ir viss kods? - Kāda tabula? Pieliec ciklā izvadi $modtime un $file; paskaties, ko vispār mēģini rakstīt masīvā. Quote Link to comment Share on other sites More sharing options...
Ownmen Posted December 11, 2009 Author Report Share Posted December 11, 2009 Paldies par palīdzību, viss sanāca. Ja kādam noder, tad kods: if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != "..") { $bilde[] = $file; } } closedir($dh); } $time = array(); foreach ($bilde as $name) { $mtime = filemtime('dir/'.$name); $time[$mtime] = $name; } krsort($time); Quote Link to comment Share on other sites More sharing options...
marcis Posted December 11, 2009 Report Share Posted December 11, 2009 Visa problēma iepriekšējā variantā bija tā, ka tu nenorādīji pilnu ceļu uz failu <? if($dh = opendir($dir)){ $files = array(); while(($file = readdir($dh)) !== false){ if(is_file($dir.'/'.$file)){ $files[filemtime($dir.'/'.$file)] = $file; } } closedir($dh); ksort($files); print_r($files); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.