dbol Posted March 22, 2007 Share Posted March 22, 2007 Hello. I've got a piece of code that almost works, minus 2 factors. The first one has to do with with the substr method, and the second is a filemtime issue. The code is as follows, and I will explain: for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != ".") || if (substr("$dirArray[$index]", -3, 3) != "ptn")) { print("<TR><TD width=60%><a href=\"Z:/Clients/$clientid/$dirArray[$index]\">$dirArray[$index]</a></td>"); print("<td width=16%><center><a href='Z:/Clients/$clientid/$dirArray[$index]'>[view]</a> <a href='insurance.php?action=deletefile&clientid=$clientid&file=$dirArray[$index]'>[remove]</a></center></td>"); echo "<td width=40%><center>" . date('M d, Y', filemtime("D:\\Clients\\$clientid\\$dirArray[$index]")) . "</center></td>"; print("</TR>\n"); } } What I'm doing here, is reading a directory using the readdir function, putting the elements into an array called $dirArray, and then cycling through a for loop and displaying all files in that directory. The problem here is, that it also displays hidden files, and my clients do not need to see them. The 2nd line of code: if (substr("$dirArray[$index]", 0, 1) != ".") || if (substr("$dirArray[$index]", -3, 3) != "ptn")) If I remove everything to the right of the OR (||), the code works fine, but I am trying to filter files that end with extension .ptn from displaying. As soon as I put that second substr back in, the page won't load properly. The second issue is with the filemtime function: echo "<td width=40%><center>" . date('M d, Y', filemtime("D:\\Clients\\$clientid\\$dirArray[$index]")) . "</center></td>"; I am trying to cycle through the files in the directory using that for loop, and print the filenames, along with their modified dates, however, the dates all show up as December 31, 1969. When I change the path to an exact path, it works fine, but won't work properly with $dirArray. Just for sake of clarity, below is the while loop used to fill the $dirArray var. while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } Link to comment https://forums.phpfreaks.com/topic/43868-solved-substr-and-readdir-issue/ Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 if (substr("$dirArray[$index]", 0, 1) != ".") || if (substr("$dirArray[$index]", -3, 3) != "ptn")) { SHOULD BE if ((substr("$dirArray[$index]", 0, 1) != ".") || (substr("$dirArray[$index]", -3, 3) != "ptn"))) { Link to comment https://forums.phpfreaks.com/topic/43868-solved-substr-and-readdir-issue/#findComment-213212 Share on other sites More sharing options...
dbol Posted March 23, 2007 Author Share Posted March 23, 2007 I will try it as soon as I get into work... the filemtime is working now, so that 1 of 2 issues solved. I'll keep you posted; thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/43868-solved-substr-and-readdir-issue/#findComment-213549 Share on other sites More sharing options...
dbol Posted March 23, 2007 Author Share Posted March 23, 2007 Almost a perfect solution... had 1 extra closing paren, and the || needed to be changed to a &&; an otherwise flawless solution. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/43868-solved-substr-and-readdir-issue/#findComment-213642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.