CG_dude Posted September 3, 2009 Share Posted September 3, 2009 Hello All, I'm ok with PHP, but this one I can not figure out. I need to hide a file that is in an array that is being generated by pulling all files except hidden files in this directory so the user doesn't see it. I know I'm close, but just can't complete it. Here is the code. <?php // open this directory $myDirectory = opendir("/users/apache/hpws/apache/htdocs/prod_report_archives"); // get each entry while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // close directory closedir($myDirectory); // count elements in array $indexCount = count($dirArray); //Print ("$indexCount files<br>\n"); // sort 'em sort($dirArray); // print 'em print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n"); print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n"); // loop through the array of files and print them all for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>"); print("<td>"); print(filetype($dirArray[$index])); print("</td>"); print("<td>"); print(filesize($dirArray[$index])); print("</td>"); print("</TR>\n"); } } print("</TABLE>\n"); ?> Thanks for any help. Quote Link to comment Share on other sites More sharing options...
CG_dude Posted September 3, 2009 Author Share Posted September 3, 2009 Sorry, forgot to add that I only want HTML files to be shown, and say there is a perl.pl file in that directory and the array pulls it, how to hide that file. Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 3, 2009 Share Posted September 3, 2009 Use continue; to skip over the files that are hidden. So, something like if(in_array($TheFileName, $TheArrayOfHiddenFiles) { continue; } Quote Link to comment Share on other sites More sharing options...
CG_dude Posted September 3, 2009 Author Share Posted September 3, 2009 Sorry, I'm not understanding that syntax or where it would go. Not familiar with "continue". Quote Link to comment Share on other sites More sharing options...
Garethp Posted September 3, 2009 Share Posted September 3, 2009 continue; just means skip. In while loops, or for loops, it just means, Go on to the next one without doing anything. So my code says, if $TheFileName is in the array $TheArrayOfHiddenFiles, then just move on, don't do anything. It goes where you commented //dont list hidden files. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.