Page 1 of 1

is_lying(is_dir()) == TRUE

Posted: Mon Jan 24, 2005 8:22 pm
by ast3r3x
So I'm making a file browser for my website and I've run into a problem. I got it working well, and I'm happy with it, but when I make a folder in the finder (windows: explorer) or even have php (0777) make a folder, when I check it with is_dir(), it returns false...why?

Code: Select all

<?php
foreach($dir as $diritem)
&#123;
	if(!eregi("^\.", $diritem))
	&#123;
		echo("<tr>\r");
		if(is_dir($basedir.$diritem)) //where it lies I think
		&#123;
			echo("stuff for a table");
			echo("stuff for a table");
		&#125;
		else
		&#123;
			$icon = fext($diritem);
			echo("stuff for a table");
			echo("stuff for a table");
			
			
			## Not Really Important ##
			
			/*$size = filesize("&#123;$basedir&#125;&#123;$dirsource&#125;&#123;$diritem&#125;");
			if($size > 1024*1024)
			&#123;
				$size = round($size/(1024*1024), 2);
				$size = "&#123;$size&#125; MB";
			&#125;
			elseif($size > 1024)
			&#123;
				$size = round($size/(1024), 2);
				$size = "&#123;$size&#125; KB";
			&#125;
			else
			&#123;
				$size = "&#123;$size&#125; bytes";
			&#125;
			echo("\t<td id="size">&#123;$size&#125;</td>\r");*/
		&#125;
		echo("</tr>\r");
	&#125;
&#125;
?>

Posted: Mon Jan 24, 2005 8:24 pm
by feyd
how is $dir filled?

Posted: Mon Jan 24, 2005 8:28 pm
by ast3r3x
Ah yes, how silly of me to tell...

$dir is filed with a scan_dir

Here is an example of it in use, the curious thing is that it isn't for all folders, just ones I'm trying to make now that I've set it up. I believe the permissions are the same on everything.

In my example, if you look in dir_image, you'll see the sub folders of that dir_image, here, and asdfadsf are all folders.

http://www.swigg.net:2222/file.php (if this doens't work let me know, I'll provide an IP link instead)

I'll provide the whole file if this isn't enough, but I just thought I'd show where I think it's going wrong, if it's not enough information, Ill show you the whole ugly script ;)...I guess maybe because I have trouble reading others stuff it isn't true about smarter people reading mine?

Posted: Mon Jan 24, 2005 8:47 pm
by ast3r3x
Just so everyone can access it...I think my DNS hates me, so here is a link with my IP, so that should work for everyone.

http://24.152.202.23:2222/file.php

Posted: Mon Jan 24, 2005 8:58 pm
by feyd
hmmmm could this be a file stat caching issue?

Posted: Mon Jan 24, 2005 9:04 pm
by ast3r3x
Who are you asking, I sure as hell hope it's not me :lol:

I added clearstatcache() to my code before my foreach loop. Didn't do anything if that is what you meant.

Posted: Mon Jan 24, 2005 11:00 pm
by rehfeld
me haves a feeling your not making sure to use directory seperators in your file paths

echo out the variable directly before using is_dir() on it

Posted: Tue Jan 25, 2005 5:00 am
by ast3r3x
I outputted the directory paths that I run through is_dir(). These are three folders I'm checking and only "dir_image" is recognized as a folder.

/Library/WebServer/swigg/files/asdfadsf

/Library/WebServer/swigg/files/dir_image

/Library/WebServer/swigg/files/here

To my knowledge, they all have the same privs set, they are real folders, and I don't see anything wrong in their directory path names.

Posted: Tue Jan 25, 2005 5:11 pm
by ast3r3x
Last hope of a spirit crushed scripter bump.

Posted: Tue Jan 25, 2005 7:37 pm
by rehfeld
have you tried making a stand alone script to check it?

make a sep script, and then do an is_dir() on a hardcoded filepath

it doesnt look like it would matter, but you might try

Code: Select all

echo getcwd() . $filepath;
to see the absolte path php is using

Posted: Tue Jan 25, 2005 8:33 pm
by ast3r3x
Color me embarrassed.... :oops:

I figured that the only thing working in my sub folders were folders that were named the same as in the base dir.

So the reason I wasn't noticing weird output with the directories is because it was telling me the wrong directory, but since it was a real one, I didn't notice the difference.

$dir_path = $basedir.$diritem;

-needs to be-

$dir_path = $basedir.$dirsource.$diritem;

So basically, is_lying(is_dir()) == FALSE && $ast3r3x == F***UP :D

Posted: Tue Jan 25, 2005 8:37 pm
by feyd
glad you figured it out..