Page 1 of 1
[SOLVED] Php Functions
Posted: Mon Jun 25, 2007 6:54 pm
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

Posted: Mon Jun 25, 2007 7:14 pm
by superdezign
What about trying the other way around,
is_file()? And you should use absolute paths.
Posted: Mon Jun 25, 2007 8:03 pm
by volka
Posted: Mon Jun 25, 2007 8:50 pm
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.
Posted: Mon Jun 25, 2007 8:58 pm
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

Posted: Mon Jun 25, 2007 9:18 pm
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.
Posted: Tue Jun 26, 2007 12:28 pm
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
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
Posted: Tue Jun 26, 2007 1:33 pm
by ziggy3000
nevermind, i did it
