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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.