iwato Posted July 11, 2010 Share Posted July 11, 2010 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 More sharing options...
boen_robot Posted July 11, 2010 Share Posted July 11, 2010 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 More sharing options...
iwato Posted July 12, 2010 Author Share Posted July 12, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.