is_lying(is_dir()) == TRUE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

is_lying(is_dir()) == TRUE

Post 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;
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how is $dir filled?
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post 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?
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hmmmm could this be a file stat caching issue?
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post 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.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post 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.
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post by ast3r3x »

Last hope of a spirit crushed scripter bump.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
ast3r3x
Forum Commoner
Posts: 95
Joined: Thu Aug 19, 2004 8:36 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

glad you figured it out..
Post Reply