Jump to content

check the second page of this, please..


ted_chou12

Recommended Posts

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.)
Link to comment
https://forums.phpfreaks.com/topic/30874-check-the-second-page-of-this-please/
Share on other sites

[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.
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.
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]
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 name
and
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.
okay, i need some experts experiences, below is the code i reproduced from the example:
[code]
<?php
foreach(@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?
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 ' &gt; <a href="'.$_SERVER['PHP_SELF'].'?dir='.urlencode($sofar).'">'.$breadcrumbs[$bi].'</a>';
}
  }
 
$baseurl = $_SERVER['PHP_SELF'] . '?dir='.$_GET['dir'] . '&amp;';
$fileurl = 'sort=name&amp;order=asc';
$sizeurl = 'sort=size&amp;order=asc';
$dateurl = 'sort=date&amp;order=asc';

switch ($_GET['sort']) {
case 'name':
if($_GET['order']=='asc') $fileurl = 'sort=name&amp;order=desc';
break;
case 'size':
if($_GET['order']=='asc') $sizeurl = 'sort=size&amp;order=desc';
break;

case 'date':
if($_GET['order']=='asc') $dateurl = 'sort=date&amp;order=desc';
break; 
default:
$fileurl = 'sort=name&amp;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]
hey, guys, sorry for revisiting this topic, but this time i will start more simpler, here is what ive got so far:
[code]
<?php
if($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.
here, ive got this far:
[code]
<?php
if($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?
okay, can anyone reply to this?
Ive got this far, and I just need a very very small push...
[code]
<?php
if($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.php
1166286036 => ..
1166474575 => topic118.txt
1166513838 => topic126.txt
1166520476 => topic118-file.php
1166520476 => topic118-lastposter.php
1166520476 => topic118-replies.htm
1166535130 => topic126-counter.php
1166536044 => topic118-counter.php
1166536253 => .
1166539196 => sort.php
but now, I only want what is after the arrow, (=>)<<<this thing.
[code]
<?php
if($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]
thanks,
<?php
if($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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.