Jump to content

Need help with this code :D


ztealmax

Recommended Posts

Hi i have this code that scans a folder and then shows content of all folders in that dir

 

<?php

$path = "news"; // Scanning folder news

foreach(glob("$path/*", GLOB_ONLYDIR) as $catdir) {
// catogories start
$catogories = ("".$catdir.".description");
$catfile = fopen($catogories, 'r') /*or die('Could not open file!')*/;
$catdata = fread($catfile, filesize($catogories)) /*or die('Could not read file!')*/;
fclose($catfile); 
$catdir = ereg_replace("news/", "", "$catdir");
echo "<a href='".$_SERVER['PHP_SELF']."?content=news'><b>".$catdir."</b></a>  ".$catdata."<br>";

}

?>

 

Now this codes is the next one when ive clicked a sub directory:

 

<?php
  
  $dir = "news/subdirectory/";
  $dh  = opendir($dir);
  while (false !== ($filename = readdir($dh))) 
{
   $pattern = '/\.news$/';
   if(preg_match($pattern,$filename))
   {
      /*    You can proceed because the file has the extension .zip       */
   $filename = ereg_replace($dir, "", "$filename");
  $filename = ereg_replace(".news", "", "$filename");
echo "<a href='?content=read&contents=".$dir."".$filename.".news'>" . $filename . "</a><br>";
   }
}

?>

 

However what i need help with is to get the info what catalog i have entered for example

if i have entered subdirectory latest i would like this code to remember or get that info

  $dir = "news/latest/";

so i need to replace "news/latest"; with some code that gets what subdir i have entered

 

How would i do something like that?

 

//Cheers

 

** BTW if my english really is that bad that i think it is, please ask if you dont understand the question ;) **

Link to comment
https://forums.phpfreaks.com/topic/57385-need-help-with-this-code-d/
Share on other sites

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.