ted_chou12 Posted December 16, 2006 Share Posted December 16, 2006 actually, my case is a little more complicated than what the title states, here, i will explain.I have a list of dir files, and I use this scrpt (by craygo):[code]<?php$namearray = array("forum"); // File names you want to exclude$extarray = array("xml","jpg","php","css","bmp","png","html"); //extension you want to exclude$files = array();if ($handle = opendir(".")) { while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".."){ if (filetype($file) == "file" || filetype($file) == "dir"){ $filearray = explode(".", $file); $files[$filearray[0]] = $filearray[1]; } } }closedir($handle);}foreach($files as $name => $ext){ if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){ } else {foreach(@file("$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message,$threadicon) = explode("#",$v);} $counteraa = file_get_contents("topic$number-counter.php"); if (!file_exists("topic$number-counter.php")){$counteraa = 0;} $repliesaa = file_get_contents("topic$number-replies.php"); if (!file_exists("topic$number-replies.php")){$repliesaa = 0;} foreach(@file("topic$number-lastposter.php") as $v){list($lastposteraa,$datetimee) = explode("#",$v);} if (!file_exists("topic$number-lastposter.php")){$lastposteraa = $name; $datetimee = $datetime;} echo "<tr height=30><td valign=center align=center bgcolor=\"#FFDEAD\">$number</td><td valign=center align=center><img src=\"../smilies/$threadicon.gif\"></td><td align=left valign=center bgcolor=\"#FFDEAD\"><a href=\"../viewtopic.php?id=$category/topic$number\"><font color=\"#A0522D\"><b>$topic</b></font></a></td><td align=center>$counteraa</td><td align=center>$repliesaa</td><td align=center bgcolor=\"#FFDEAD\">$name</td><td align=center>$datetimee</td><td align=center bgcolor=\"#FFDEAD\">$lastposteraa</td></tr>"."\n";}}?>[/code]Yeap, although i want to list the text files, but the modification time is not actually the filemtime() of the text files, the real modification time is stored in the "topic$number-lastposter.php" files, and taken out through the explode function into the "$datetimee" string, therefore, this makes the whole thing harder...could anyone give me some suggestions?(as you can see, I am trying to build a forum, you may ask why dont i just install forum templates such as phpbb or smf? I want to build a forum out of scratch so I can learn more.) Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/ Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 [code]if($handle = opendir(".")){ while (false !== ($file = readdir($handle))){ if($file != "." && $file != ".."){ if(filetype($file) == "file" || filetype($file) == "dir"){ $files[date("FdYHis", filemtime($file)] = $file; } } } closedir($handle);}ksort($files); #you may want a different sort here...[/code]then afterwards, you explode $file on the spot. Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142385 Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 thank you so much!but may i let you know if i have any difficulties further on?thanks for your interest in my problem :D Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142389 Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 sure, you can drop a message here, or just pm me... either works :-) Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142392 Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 thank you.I put the two of them together like this:[code]<?php$namearray = array("forum"); // File names you want to exclude$extarray = array("xml","jpg","php","css","bmp","png","html"); //extension you want to exclude$files = array();if ($handle = opendir(".")) { while (false !== ($file = readdir($handle))) { if($file != "." && $file != ".."){ if (filetype($file) == "file" || filetype($file) == "dir"){ $filearray = explode(".", $file); $files[date("FdYHis"), filemtime($file)] = $file; } } }closedir($handle);}ksort($files);foreach($files as $name => $ext){ if(in_array($name, $namearray, false) || in_array($ext, $extarray, false)){ } else {foreach(@file("$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message,$threadicon) = explode("#",$v);} $counteraa = file_get_contents("topic$number-counter.php"); if (!file_exists("topic$number-counter.php")){$counteraa = 0;} $repliesaa = file_get_contents("topic$number-replies.php"); if (!file_exists("topic$number-replies.php")){$repliesaa = 0;} foreach(@file("topic$number-lastposter.php") as $v){list($lastposteraa,$datetimee) = explode("#",$v);} if (!file_exists("topic$number-lastposter.php")){$lastposteraa = $name; $datetimee = $datetime;} echo "<tr height=30><td valign=center align=center bgcolor=\"#FFDEAD\">$number</td><td valign=center align=center><img src=\"../smilies/$threadicon.gif\"></td><td align=left valign=center bgcolor=\"#FFDEAD\"><a href=\"../viewtopic.php?id=$category/topic$number\"><font color=\"#A0522D\"><b>$topic</b></font></a></td><td align=center>$counteraa</td><td align=center>$repliesaa</td><td align=center bgcolor=\"#FFDEAD\">$name</td><td align=center>$datetimee</td><td align=center bgcolor=\"#FFDEAD\">$lastposteraa</td></tr>"."\n";}}?>[/code]But it doesn't work, what could I possibly do wrong?Thanks Ted. Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142398 Share on other sites More sharing options...
taith Posted December 16, 2006 Share Posted December 16, 2006 something to this effect... explode on the other side of that array...[code]<?php$namearray = array("forum");$extarray = array("xml","jpg","php","css","bmp","png","html"); $files = array();if($handle = opendir(".")){ while (false !== ($file = readdir($handle))){ if($file != "." && $file != ".."){ if(filetype($file) == "file" || filetype($file) == "dir"){ $files[date("FdYHis"), filemtime($file)] = $file; } } } closedir($handle);}ksort($files);foreach($files as $v){ $filearray = explode(".", $v); $name=$filearray[0]; $ext=$filearray[1]; if(!(in_array($name, $namearray, false) || in_array($ext, $extarray, false))){ foreach(@file("$name.txt") as $v) list($topic,$category,$number,$datetime,$name,$username,$message,$threadicon) = explode("#",$v); $counteraa = file_get_contents("topic$number-counter.php"); if(!file_exists("topic$number-counter.php")) $counteraa = 0; $repliesaa = file_get_contents("topic$number-replies.php"); if(!file_exists("topic$number-replies.php")) $repliesaa = 0; foreach(@file("topic$number-lastposter.php") as $v) list($lastposteraa,$datetimee) = explode("#",$v); if(!file_exists("topic$number-lastposter.php")){ $lastposteraa = $name; $datetimee = $datetime; } echo "<tr height=30><td valign=center align=center bgcolor=\"#FFDEAD\">$number</td><td valign=center align=center><img src=\"../smilies/$threadicon.gif\"></td><td align=left valign=center bgcolor=\"#FFDEAD\"><a href=\"../viewtopic.php?id=$category/topic$number\"><font color=\"#A0522D\"><b>$topic</b></font></a></td><td align=center>$counteraa</td><td align=center>$repliesaa</td><td align=center bgcolor=\"#FFDEAD\">$name</td><td align=center>$datetimee</td><td align=center bgcolor=\"#FFDEAD\">$lastposteraa</td></tr>"."\n"; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142403 Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 thanks for your help, but it doesnt work.. i think i will start over, below is what i got from php.net:[code]<?php$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");ksort($fruits);foreach ($fruits as $key => $val) { echo "$key = $val\n";}?>[/code]instead of letters "a", "b", "c", "d"i have the file names in a single array, what i need to do now is to put my mod. time in place of "apple" and "banana".so o need to put the two into a single array.if$name is the file nameand foreach(@file("$name.txt") as $v){list($topic,$category,$number,$datetime,$name,$username,$message,$threadicon) = explode("#",$v);}foreach(@file("topic$number-lastposter.php") as $v){list($lastposteraa,$datetimee) = explode("#",$v);} if (!file_exists("topic$number-lastposter.php")){$lastposteraa = $name; $datetimee = $datetime;}the $datetimee is my mod. time, what do i need to do to put two of them into a single array like the one above?Thanks Ted. :D we are getting close. Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142414 Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 okay, i need some experts experiences, below is the code i reproduced from the example:[code]<?phpforeach(@file("$files") as $v){list($topic,$category,$number,$datetime,$name,$username,$message,$threadicon) = explode("#",$v);}foreach(@file("topic$number-lastposter.php") as $v){list($lastposteraa,$datetimee) = explode("#",$v);}if (!file_exists("topic$number-lastposter.php")){$lastposteraa = $name; $datetimee = $datetime;}$arraysort = array(foreach($files){echo"\"$datetimee\" => \"$name\",";});#especially this part!!!ksort($arraysort);foreach ($arraysort as $datetimee => $name) {echo "$datetimee = $name\n";}?>[/code]theriotically, would this work? Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142445 Share on other sites More sharing options...
ted_chou12 Posted December 16, 2006 Author Share Posted December 16, 2006 below is extracted out of a list directory script, may be it can help me in some way, so can any php experts explain this to me? thanks so much!![code] <?php $breadcrumbs = split('/', $leadon); if(($bsize = sizeof($breadcrumbs))>0) { $sofar = ''; for($bi=0;$bi<($bsize-1);$bi++) { $sofar = $sofar . $breadcrumbs[$bi] . '/'; echo ' > <a href="'.$_SERVER['PHP_SELF'].'?dir='.urlencode($sofar).'">'.$breadcrumbs[$bi].'</a>'; } } $baseurl = $_SERVER['PHP_SELF'] . '?dir='.$_GET['dir'] . '&'; $fileurl = 'sort=name&order=asc'; $sizeurl = 'sort=size&order=asc'; $dateurl = 'sort=date&order=asc'; switch ($_GET['sort']) { case 'name': if($_GET['order']=='asc') $fileurl = 'sort=name&order=desc'; break; case 'size': if($_GET['order']=='asc') $sizeurl = 'sort=size&order=desc'; break; case 'date': if($_GET['order']=='asc') $dateurl = 'sort=date&order=desc'; break; default: $fileurl = 'sort=name&order=desc'; break; } ?> </div> <div id="listingcontainer"> <div id="listingheader"> <div id="headerfile"><a href="<?=$baseurl . $fileurl;?>">File</a></div> <div id="headersize"><a href="<?=$baseurl . $sizeurl;?>">Size</a></div> <div id="headermodified"><a href="<?=$baseurl . $dateurl;?>">Last Modified</a></div> </div> <div id="listing"> <? $class = 'b'; if($dirok) { ?> <div><a href="<?=$_SERVER['PHP_SELF'].'?dir='.urlencode($dotdotdir);?>" class="<?=$class;?>"><img src="dlf/dirup.png" alt="Folder" /><strong>..</strong> <em>-</em> <?=date ("M d Y h:i:s A", filemtime($dotdotdir));?></a></div> <? if($class=='b') $class='w'; else $class = 'b'; } $arsize = sizeof($dirs); for($i=0;$i<$arsize;$i++) { ?> <div><a href="<?=$_SERVER['PHP_SELF'].'?dir='.urlencode($leadon.$dirs[$i]);?>" class="<?=$class;?>"><img src="dlf/folder.png" alt="<?=$dirs[$i];?>" /><strong><?=$dirs[$i];?></strong> <em>-</em> <?=date ("M d Y h:i:s A", filemtime($leadon.$dirs[$i]));?></a></div> <? if($class=='b') $class='w'; else $class = 'b'; } $arsize = sizeof($files); for($i=0;$i<$arsize;$i++) { $icon = 'unknown.png'; $ext = strtolower(substr($files[$i], strrpos($files[$i], '.')+1)); $supportedimages = array('gif', 'png', 'jpeg', 'jpg'); $thumb = ''; if($showthumbnails && in_array($ext, $supportedimages)) { $thumb = '<span><img src="dlf/trans.gif" alt="'.$files[$i].'" name="thumb'.$i.'" /></span>'; $thumb2 = ' onmouseover="o('.$i.', \''.urlencode($leadon . $files[$i]).'\');" onmouseout="f('.$i.');"'; } if($filetypes[$ext]) { $icon = $filetypes[$ext]; } $filename = $files[$i]; if(strlen($filename)>43) { $filename = substr($files[$i], 0, 40) . '...'; } $fileurl = $leadon . $files[$i]; if($forcedownloads) { $fileurl = $_SESSION['PHP_SELF'] . '?dir=' . urlencode($leadon) . '&download=' . urlencode($files[$i]); } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-142477 Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 hey, guys, sorry for revisiting this topic, but this time i will start more simpler, here is what ive got so far:[code]<?phpif($handle = opendir(".")){while (false !== ($file = readdir($handle))){//how do you put all the files in to a single array?}closedir($handle);}ksort($file);echo "$file<br>\n";?>[/code]now, I want to put all the files read in the dir to an single array so I can sort them. Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144414 Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 [code]<?phpif($handle = opendir(".")){ while(false !== ($file = readdir($handle))){ $files[]=$file; } closedir($handle);}ksort($files);foreach($files as $file) echo "$file<br>\n";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144420 Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 thanks taith! :D Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144425 Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 here, ive got this far:[code]<?phpif($handle = opendir(".")){ while(false !== ($file = readdir($handle))){ $mtime = filemtime($file); $files[]=$mtime; } closedir($handle);}sort($files);foreach($files as $file)echo "$file<br>\n";?>[/code]but it echoes me the filemtime not the filename, how do i change it back to filename? Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144434 Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 okay, can anyone reply to this?Ive got this far, and I just need a very very small push...[code]<?phpif($handle = opendir(".")){ while(false !== ($file = readdir($handle))){ $mtime = filemtime($file); $files[]="$mtime => $file"; } closedir($handle);}sort($files);foreach($files as $file)echo "$file<br>\n";?>[/code]the results of this gives you this:1166111520 => index.php1166286036 => ..1166474575 => topic118.txt1166513838 => topic126.txt1166520476 => topic118-file.php1166520476 => topic118-lastposter.php1166520476 => topic118-replies.htm1166535130 => topic126-counter.php1166536044 => topic118-counter.php1166536253 => .1166539196 => sort.phpbut now, I only want what is after the arrow, (=>)<<<this thing. Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144449 Share on other sites More sharing options...
taith Posted December 19, 2006 Share Posted December 19, 2006 [code]<?phpif($handle = opendir(".")){ while(false !== ($file = readdir($handle))){ if(($file!='.')&&($file!='..')){ $files[filemtime($file)]=$file; } } closedir($handle);}sort($files);foreach($files as $file) echo "$file<br>\n";?>[/code]or just[code]$file=explode('=>',$file);echo trim($file[1]);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144457 Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 thanks,<?phpif($handle = opendir(".")){ while(false !== ($file = readdir($handle))){ $mtime = filemtime($file); $files[]="$mtime => $file"; } closedir($handle);}sort($files);foreach($files as $v){list($filemtime,$filename) = explode(" => ",$v);echo "$filename<br>\n";}?>this one worked!!!!but how do i get it in the oppisite order( ie. latest first.) Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144466 Share on other sites More sharing options...
HuggieBear Posted December 19, 2006 Share Posted December 19, 2006 Try [url=http://uk.php.net/manual/en/function.array-reverse.php]array_reverse()[/url].RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144472 Share on other sites More sharing options...
ted_chou12 Posted December 19, 2006 Author Share Posted December 19, 2006 okay thanks. ;D Quote Link to comment https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/#findComment-144477 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.