ztealmax Posted March 7, 2009 Share Posted March 7, 2009 Hello all having a bit of problem with this code think anyone can help me? <?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 .news */ $filename = ereg_replace($dir, "", "$filename"); $filename = ereg_replace(".news", "", "$filename"); echo "<a href='?content=read&contents=".$dir."".$filename.".news'>" . $filename . "</a><br>"; } } ?> the problem im having that im getting this error message readdir(): supplied argument is not a valid Directory resource ni news.php if you need any more information please just ask, if you want all files just ask i will supply them you can add me to msn if you want martin@ztealmax.se //Cheers Martin "Ztealmax" Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi What are you setting $path to? All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 think in this code im setting path to what i press on <?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>"; } ?> if im being unclear please say so my english isnt the best i can send you the files if you want? demo site here: http://demo.premierguild.com Sincerely Martin Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Suspect it might be where it thinks "news" is. Does the directory the script lives in have a subdirectory called "news"? All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 Hi Suspect it might be where it thinks "news" is. Does the directory the script lives in have a subdirectory called "news"? All the best Keith yea it has a directory called news like this: News/ and in news i have subdirectorys called for example News/Info all php files are in the root /sincerely Martin Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Echo out $news just before while (false !== ($filename = readdir($dh))) in the original script. All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 tried it , doesnt work, idont know what im doing wrong :\ Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi What was the value of $news when echoed out? If necessary put some * either side to check if it is really empty or spaces. All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 Hi What was the value of $news when echoed out? If necessary put some * either side to check if it is really empty or spaces. All the best Keith the echo was empty didnt show up anything think the fault is in this code while (false !== ($filename = readdir($dh)))[/Code] Warning: readdir(): supplied argument is not a valid Directory resource in news.php on line 26 Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Realised I have made a mistake. What I meant to say to echo out was the contents of $path (which appeared to have been set to "news"), or $dir that you have assigned $path to All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 hi ok echod path but still got nothing showing still get this message Warning: readdir(): supplied argument is not a valid Directory resource in news.php on line 26 Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 i can give u access to ftp if you would like to check it out first hand? ive sended you a PM with information for ftp Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 7, 2009 Share Posted March 7, 2009 Hi Maybe later, but there are a few things I need to do now. Might be easiest to just post the script. I suspect that $path has been reset somewhere. All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 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>"; } ?> 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; echo $path; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $pattern = '/\.news$/'; if(preg_match($pattern,$filename)) { /* You can proceed because the file has the extension .news */ $filename = ereg_replace($dir, "", "$filename"); $filename = ereg_replace(".news", "", "$filename"); echo "<a href='?content=read&contents=".$dir."".$filename.".news'>" . $filename . "</a><br>"; } } ?> this is my index.php <?php // language start $language = ("config/language.cfg"); $lanfile = fopen($language, 'r') /*or die('Could not open file!')*/; $landata = fread($lanfile, filesize($language)) /*or die('Could not read file!')*/; fclose($lanfile); include("languages/$landata.php"); // language end ?> <?php // sitename start $sitename = ("config/sitename.cfg"); $sitenamefile = fopen($sitename, 'r') /*or die('Could not open file!')*/; $sitenamedata = fread($sitenamefile, filesize($sitename)) /*or die('Could not read file!')*/; fclose($sitenamefile); define('sitename',$sitenamedata.""); // sitename end ?> <?php // welcome start $welcome = ("config/welcome.cfg"); $welcomefile = fopen($welcome, 'r') /*or die('Could not open file!')*/; $welcomedata = fread($welcomefile, filesize($welcome)) /*or die('Could not read file!')*/; fclose($welcomefile); define('welcome',$welcomedata.""); // welcome end ?> <?php // sitetag start $sitetag = ("config/sitetag.cfg"); $sitetagfile = fopen($sitetag, 'r') /*or die('Could not open file!')*/; $sitetagdata = fread($sitetagfile, filesize($sitetag)) /*or die('Could not read file!')*/; fclose($sitetagfile); define('sitetag',$sitetagdata.""); // sitetag end ?> <?php // disclaimer start $disclaimer = ("config/disclaimer.cfg"); $disclaimerfile = fopen($disclaimer, 'r') /*or die('Could not open file!')*/; $disclaimerdata = fread($disclaimerfile, filesize($disclaimer)) /*or die('Could not read file!')*/; fclose($disclaimerfile); define('disclaimer',$disclaimerdata.""); // disclaimer end ?> <?php // theme start $theme = ("config/theme.cfg"); $themefile = fopen($theme, 'r') /*or die('Could not open file!')*/; $themedata = fread($themefile, filesize($theme)) /*or die('Could not read file!')*/; fclose($themefile); $themes = ("themes/"); define('theme',$themes.$themedata."/"); @include_once("$themes/$themedata/theme.php"); // theme end ?> <?php $url = $_SERVER['SERVER_NAME']; define("url", $_SERVER['SERVER_NAME']); ?> <? echo $header ?> <? include("menus/mainmenu.php");?> <?php if(isset($_GET['content'])){ include($_GET['content'].".php"); } else { include($_GET['content'].""); echo "".$welcomedata." "; } ?> <? echo $footer ?> Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 7, 2009 Author Share Posted March 7, 2009 still need some help here Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi Are those the full scripts? All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 8, 2009 Author Share Posted March 8, 2009 Hi Are those the full scripts? All the best Keith yes it should be the complete scripts Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi There is nothing in news.php assigning a value to $path . It is assigned in news_catogories.php, but that isn't included in news.php. Do you have register globals turned on? All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 8, 2009 Author Share Posted March 8, 2009 hmm where would i turn that on? damn im such a noob at this /Martin Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 8, 2009 Author Share Posted March 8, 2009 hmm where would i turn that on? damn im such a noob at this /Martin path thats assigned in news_catogories.php is "news/" but when i click a link within "news/" it should become the new path for "news.php" for example i click info so the new path should now be "news/info" let me know if im bad at explaining! //martin Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi Not sure if I am missing something, but news_catogories.php doesn't seem to link to news.php. If you do go to news.php then there is nothing in news.php to set the variable $path. An exception to this would be if register_globals was turned on, where you could set $path in the query string. This used to be on by default and is now off by default as it makes it rather too easy to write insecure code. Or do you have an overall script that includes news.php, news_categories.php, etc? All the best Keith Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 8, 2009 Author Share Posted March 8, 2009 im checking tru the code get back to you soon Quote Link to comment Share on other sites More sharing options...
zggtf211 Posted March 8, 2009 Share Posted March 8, 2009 I just looked at php.net's manual about readdir and when comparing it to another value, it says to use '===' that might make a difference Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 8, 2009 Author Share Posted March 8, 2009 ok i cant find whats wrong or where to change it demo site is: demo.premierguild.com ftp is the same as a messaged you about register globals is on as far as iknow! what this code should do is somehow get the real path of the link i clicked, does it make any sence? //Cheers Martin Quote Link to comment Share on other sites More sharing options...
kickstart Posted March 8, 2009 Share Posted March 8, 2009 Hi Right, looking at that you have index.php. That takes a parameter of the other script to include. When you click on one of your news menu it passes ?content=news_catagories, causing it to include news_categories.php . This works fine. However when you get a list of the various news categories it passes content=news, causing it to include news.php . However neither index.php nor news.php set the value of $path (it is set in news_categories.php, which isn't being included this time round). Hence no argument for readdir. You need to pass across a value for $path. How you do this I am not sure, possibly an extra parameter (possibly changing news_categories.php with the line echo "<a href='".$_SERVER['PHP_SELF']."?content=news&path=somepath'><b>".$catdir."</b></a> ".$catdata."<br>";. However this is pretty insecure (so is passing over the script name to include in content=news). I would make very certain you vaidate the input before doing the includes. All the best Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.