• 28-09-2007, 07:04:51
    #1
    Belirli bir dizindeki dosyaları yazdırdım, ancak bunları değiştirilme tarihlerine göre sıralamak istiyorum.

    Sıralama kriteri $last_modified değişkenine göre olacak, aklımda ksort() var, ancak bunun için tarihleri array() içine almak lazım.

    // get file list
    function get_file_list($file_path) 
    {
    	global $path;
        $opendir = opendir($file_path);
        while ( gettype($file = readdir($opendir) ) != boolean ) 
    	{
            if ( is_file("$file_path/$file") && ($file !='index.html') && ($file !='index.htm') && ($file !='.htaccess') ) 
    		{
    			// Change to the name of the file
    			$last_modified = filemtime($file_path . $file);
    			echo '<ul class="detals_list">';
    			//echo '<li><strong>' . date("dS F, Y H:i T", $last_modified) . '</strong></li>';
    			echo '	<li><strong>' . turkce_tarih($last_modified) . '</strong></li>';
    			echo '	<li class="download"> <strong><a href="' . $file_path . $file . '" title="' . $file . '">İndir</a></strong> [' . get_filesize(filesize($path . $file)) . ']</li>';
    			echo '	<li><span class="gensmall" style="color:gray">' . md5_file($path . $file) . '</span></li>';
    			echo '</ul>';
            }
        }
        closedir ($opendir);
    }
    şu çalışan örnek te burada: http://phpbb3.canversoft.net/
  • 28-09-2007, 15:01:05
    #2
    Üyeliği durduruldu
    en üstte $dizi = array(); yarat sonra $dizi[$last_modified] Buna yazılacak değerleri atarsın en sonunda ksort($dizi[$last_modified])
    foreach($dizi[$last_modified] in $veri){
    echo eval($veri);
    }

    Şeklinde falan dene bir? Deneme fırsatım olmadı ama aklıma geldi böyle birşey.
  • 28-09-2007, 15:50:08
    #3
    onu denedim, while içinde kullanamadım, while sonrasına aldığımda ise, diğer değişkenler içeride kalıyor.
  • 28-09-2007, 16:09:39
    #4
    Üyeliği durduruldu
    fonksiyonun içinde tanımlamadınmı?

    // get file list 
    function get_file_list($file_path)  
    { 
        global $path; 
    $dizi = array();
        $opendir = opendir($file_path); 
        while ( gettype($file = readdir($opendir) ) != boolean )  
        { 
            if ( is_file("$file_path/$file") && ($file !='index.html') && ($file !='index.htm') && ($file !='.htaccess') )  
            { 
                // Change to the name of the file 
                $last_modified = filemtime($file_path . $file); 
                $dizi[$last_modified] = '<ul class="detals_list">'; 
                //echo '<li><strong>' . date("dS F, Y H:i T", $last_modified) . '</strong></li>'; 
                $dizi[$last_modified] .='    <li><strong>' . turkce_tarih($last_modified) . '</strong></li>'; 
                $dizi[$last_modified] .= '    <li class="download"> <strong><a href="' . $file_path . $file . '" title="' . $file . '">İndir</a></strong> [' . get_filesize(filesize($path . $file)) . ']</li>'; 
                $dizi[$last_modified] .= '    <li><span class="gensmall" style="color:gray">' . md5_file($path . $file) . '</span></li>'; 
                $dizi[$last_modified] .= '</ul>'; 
            } 
        } 
        closedir ($opendir); 
    ksort($dizi[$last_modified])
     foreach($dizi[$last_modified] in  $veri){
     echo eval($veri);
     }
    }
  • 28-09-2007, 16:12:43
    #5
    Ne var ne yoksa array() elemanı yaptım, çalıştırdım, böyle daha iyi oldu sanırım.

    İlhamı ksort() yerine rsort() kullanmam gerektiğini anlayıp rsort() örneklerine bakınca aldım.


    // get file list
    function get_file_list($file_path) 
    {
    	global $path;
        $opendir = opendir($file_path);
        while ( gettype($file = readdir($opendir) ) != boolean ) 
    	{
            if ( is_file("$file_path/$file") && ($file !='index.html') && ($file !='index.htm') && ($file !='.htaccess') ) 
    		{
    			$title = $file;
    			$file = $file_path . $file;
    			$files[] = array(
    				'last_modified' => turkce_tarih(filemtime($file)),
    				'file' 			=> $file,
    				'title'			=> $title,
    				'filesize' 		=> get_filesize(filesize($file)),
    				'md5_file'		=> md5_file($file)
    			);
    			// debug
    			//print_r(array_values($dizi_file));
            }
        }
        closedir ($opendir);
    	if ($files)
    	{
    		rsort($files); #sorts by filemtime
    		#done! Show the files sorted by modification date
    		foreach ($files as $file)
    		{
    			//echo "$file[last_modified] $file[1]<br />\n";
    			echo '<ul class="detals_list">';
    			echo '	<li><strong>' . $file[last_modified] . '</strong></li>';
    			echo '	<li class="download"> <strong><a href="' . $file[file] . '" title="' . $file[title] . '">İndir</a></strong> [' . $file[filesize] . ']</li>';
    			echo '	<li><span class="gensmall" style="color:gray">' . $file[md5_file] . '</span></li>';
    			echo '</ul>';
    		}
    	}
    }
  • 02-10-2007, 19:45:13
    #6
    edit: yaptım