Jump to content

The filetype( ) Function


iwato

Recommended Posts

QUESTION: How might one explain the failure of the filetype( ) function in the following code block to produce a valid filetype -- namely, "dir" -- for folders containing other folders and files.

<?php	$folderpath = "../../../";	if (is_dir($folderpath)) {		if ($handle = opendir($folderpath)) {			while (($folder = readdir($handle)) == !false) {				echo "Name of folder: " . $folder . "<br />";				echo "Type of file: " . filetype($folder) . "<br /><br />";				clearstatcache();			}		}		closedir();	} else {		echo "$folderpath is not a path to a folder.";	}?>

RECURRING ERROR MESSAGE: Warning: filetype() [function.filetype]: Lstat failed for constants in /Applications/MAMP/htdocs/php-practice/functions/directory/closedir/closedir.php on line 42.Line 42 corresponds to the line of code that contains the filetype( ) function. Mind you, this recurring error message does not return a warning for a folder named _notes whose filetype is returned as dir -- the value that I expected to see for all of the other folders.Roddy

Link to comment
Share on other sites

Well, the error message says it... this functions calls lstat() in order to find out more about the path, and that call fails. This can happen due permissions issues. In particular, I think the folder needs to be executable, which in folder context means traversable.

Link to comment
Share on other sites

Well, the error message says it... this functions calls lstat() in order to find out more about the path, and that call fails. This can happen due permissions issues. In particular, I think the folder needs to be executable, which in folder context means traversable.
After some experimentation ending in the execution of the handy var_dump() function, I have realized that the problem is with the readdir() function. The readdir( ) function returns only the name of the file -- not a path to it. Problem solved.In any case, thanks for the effort. It makes all the difference.By the way, I now have a fairly good handle on permissions thanks to everyone's help and strangely enough TextWrangler.Roddy With each new command zero to several new techniques.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...