stat() weirdness

From: Date: Sat, 24 Jun 2000 01:21:53 +0000
Subject: stat() weirdness
Groups: php.general 
Request: Send a blank email to php-general+get-2939@lists.php.net to get a copy of this message
I'm designing a file manager for my web site, enabling me to upload/download/etc. without using FTP at all. So far, the results are looking very nice, even restricting certain employees to only access certain directories without bothering filesystem permissions. However, I'm having some problems when it comes to directory listings. I want to print the filename, links, device type, size in bytes, and last modified date for each file. I also want to be able to tell if the filename is a directory or not, so I can click it and move into that directory. I'm using the stat() function to grab this info. The problem is that sometimes stat() returns nothing, as does is_dir(), is_file(), and is_link()! The filename prints fine, but the other columns contain nothing (except for the last modified column, which contains "1969-12-31 19:00" (the unix epoch?)). I've tried this code with and without clearstatcache(), it doesn't seem to make any difference. Any ideas? Here's a chunk of code (a bit long): $theDir = opendir($currentDir); while($filename = readdir($theDir)) { $statInfo = stat($filename); print ("<tr bgcolor=\"$theColor\">"); print ("<td>"); if (is_dir($filename)) { ?><img src="icons/folder.gif" height="16" width="16" alt="" border="0"> <?php $linkDir = $currentDir; $linkDir .= "/"; $linkDir .= $filename; ?> &nbsp;&nbsp; <a href="file_manager.phtml?currentDir=<?php print $linkDir; ?>"> <?php print $filename; print ("</td>"); } else { if (is_file($filename)) { ?><img src="icons/file.gif" height="16" width="16" alt="" border="0"><?php } if (is_link($filename)) { ?><img src="icons/link.gif" height="16" width="16" alt="" border="0"><?php } print ("&nbsp;&nbsp;$filename</td>"); } print ("<td align=\"right\">$statInfo[3]</td>"); //Links print ("<td align=\"right\">$statInfo[6]</td>"); //Device type print ("<td align=\"right\">$statInfo[7]</td>"); //Size (bytes) print ("<td align=\"right\">"); print date("Y-m-d H:i", $statInfo[9]); //Last Modified date print ("</td>"); print ("</tr>"); } TIA, Ben Gollmer Jatosoft, LLC http://www.jatosoft.com/

« previous php.general (#2939) next »