Jump to content

Warning: readdir(): supplied argument is not a valid Directory resource


ztealmax

Recommended Posts

Hello i have a problem with this code doesnt seem to get it working, anyone got an idea what i made wrong?

 

<?php
  function in_dir ($file, $in_dir)
  {
      $dir    = realpath ($file);
      $in_dir = realpath ($in_dir);

      if (!is_dir ($file)) {
          $dir = dirname ($file);
      }

      do {
          if ($dir === $in_dir) {
              $is_in_dir = TRUE;
              break;
          }
      } while ($dir !== ($dir = dirname ($dir)));

      return (bool) @$is_in_dir;
  }
  $dir = $path;
echo $dir;
  $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>";
   }
}

?>

ok got some more information here so perhaps you can help me easier ;)

 

have this file (this file list all folders within the folder news

and the folders are the catogories this code works

and a text file is also created that i opens with this file called Server.description

 

so 1 - it scans folder and display all foldernames as catogories, and then opens the textfile

and displays catogories description

 

news_catogories.php

<?php

$path = "news"; // path to the dir you want to scan

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 when i click a catogories name for example lest call the catogory " INFO "

it should now scan what files are in it and show it as a list

 

files are called in this example:

info.news (text file)

info.png (image)

 

this is within the root:

news.php

<?php
  function in_dir ($file, $in_dir)
  {
      $dir    = realpath ($file);
      $in_dir = realpath ($in_dir);

      if (!is_dir ($file)) {
          $dir = dirname ($file);
      }

      do {
          if ($dir === $in_dir) {
              $is_in_dir = TRUE;
              break;
          }
      } while ($dir !== ($dir = dirname ($dir)));

      return (bool) @$is_in_dir;
  }
  $dir = $path;
echo $dir;
  $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>";
   }
}

?>

 

this is how directory tree looks like:

 

..

News\

- news\Info\ (this is catogory)

- news\Info\info.news

- news\Info\info.png

- news\Info.description (txt file to describe this)

 

Themes\

Config\

languages\

menus\

index.php

news.php

news_catogories.php

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.