ztealmax Posted March 6, 2009 Share Posted March 6, 2009 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>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/148213-warning-readdir-supplied-argument-is-not-a-valid-directory-resource/ Share on other sites More sharing options...
ztealmax Posted March 6, 2009 Author Share Posted March 6, 2009 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 Link to comment https://forums.phpfreaks.com/topic/148213-warning-readdir-supplied-argument-is-not-a-valid-directory-resource/#findComment-778185 Share on other sites More sharing options...
ztealmax Posted March 6, 2009 Author Share Posted March 6, 2009 http://demo.premierguild.com/ this is the site its on, please check it out to get basic idea of what im asking for *** NEED HELP *** Link to comment https://forums.phpfreaks.com/topic/148213-warning-readdir-supplied-argument-is-not-a-valid-directory-resource/#findComment-778544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.