Jump to content

How to hide a file in array so it is not seen by the user


CG_dude

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.