Jump to content

If statement to remove file name from displaying in php list


jonw118

Recommended Posts

I am using the following php script to display all the files that are uploaded in a directory on a page. There are two files in the folder I do not want displayed: .htaccess & index.php.

 

Can someone help me out and provide a little guidance about what I need to do to print all the file names EXCEPT for those two. I imagine some sort of if statement.

 

CODE:

 

Top of page:

<?php
$dirname = ".";
$dir = opendir($dirname);
?>

 

Body:

<?php
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
echo("<a href='$dirname$file'>$file</a> <br />");
}
}
?>

 

Thanks so much!

if($handle = opendir('.')){
while(false !== ($file = readdir($handle))){
	if($file != '.' && $file != '..' && $file != 'index.php' && $file != '.htaccess'){
		echo '<br />
<a href="'.$file.'">'.$file.'</a>';
	}
}
closedir($handle);
}

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.