[SOLVED] Php Functions

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
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

[SOLVED] Php Functions

Post by ziggy3000 »

is there a function that tells you that a file is a folder? i am creating a file manager(pretty good so far) and i need to know if there is a function that lets me find out that it is not a file, but a folder. is_dir doesn't work on
./blah/abc/
and i need to able to use it on that so i cant use that function...

any help is appreciated
:)
Last edited by ziggy3000 on Tue Jun 26, 2007 1:33 pm, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What about trying the other way around, is_file()? And you should use absolute paths.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

for is_dir
when you try
var_dump(is_dir('bogus_dir/abc')) . "\n";
it returns false. i need it to return true.
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

i need this because i am creating a file manager and this snippet of code echos out the appropriate icon for each file

Code: Select all

function icon($file){
	$ext = ext($file);
	$files = array(
				"code" => array("php", "js", "asp", "sql"),
				"image" => array("png", "jpg", "ico", "gif", "psd", "art", "tif", "tiff", "jpeg", "jpe"),
				"compressed" => array("zip", "tar", "rar", "7z", "gz", "iso", "tgz"),
				"unknown" => array("dll", "ttf"),
				"movie" => array("avi", "mp4", "mpeg", "wmv", "mpg"), 
				"word" => array("doc", "docx", "pdf", "ppt", "pptx", "xlsm", "xlsx", "xls", "docm", "dotx", "dotm", "xltm", "xltx", "potx", "potm", "ppam", "sldx", "sldm", "thmx", "ppsx", "ppsm"),
				"text" => array("txt"),
				"web" => array("html", "htm"),
				"style" => array("css")
			);

	foreach($files as $icon => $exts){
		if(in_array($ext, $exts)){
			echo "<img src='./img/fileman/$icon.png' alt='$ext' height='16' width='16' />";
		}
		if (is_dir($file)){
			echo "<img src='./img/fileman/folder.png' alt='Folder' height='16' width='16' />";
		}
	}
}
it echo's out every image except for the folder one. i need it to echo out folder.png if $file is a directory. but it doesn't :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why is $file being checked if it's a directory in a loop? Shouldn't it be outside that loop and control whether said loop is run or not?

is_dir() requires the path to exist for it to check. It probably doesn't understand your supplied information.
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

its in a loop because it only prints out the image, so you can tell by looking at that image whether it's a directory, or a file.
i have another function that scans all files and folders in a certain directory, and echos that out. that works great, so no problem with that :D

i need it so scan each file and folder, and if it's a folder, it echos out folder.png. if it's a file, it prints out the appropriate icon. so far, only the folder icon is the only icon that doesn't get printed out
fyi, the files do exist that are being used in the function i posted
ziggy3000
Forum Contributor
Posts: 205
Joined: Fri Mar 23, 2007 3:04 pm

Post by ziggy3000 »

nevermind, i did it :D
Post Reply