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.

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.