Jump to content

Recommended Posts

Hullo, I wrote this script for my website and I can't figure out how I can exclude directories and files from it.

 

http://test.neverpool.com/sitemap.php

 

Here's the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Directory Contents</title>
<style type="text/css">
a:link {color:#000000;}    /* unvisited link */
a:visited {color:#FF0000;} /* visited link */
a:hover {color:#000099;}   /* mouse over link */
a:active {color:#FF0000;}  /* selected link */
</style>

</head>
<body>
<?php
/* This script is copyrighted by NeverPool.com if you have any questions, email me. Creechl84@gmail.com.  COPYRIGHT 2009-2010 */
$dir = '.';
$dateformat = 'F j, Y';

$file = glob($dir . '/*');

$dirs = array();
$files = array();

foreach ($file as $f)
{
    if (is_dir($f)) $dirs[] = $f;
    else            $files[] = $f;
}

echo '<ul>';
foreach ($dirs as $d)
{
    $base = basename($d);
    echo "<li><a href=\"$base\">$base</a>";
}
echo '</ul>';

echo '<table>';
echo '<thead><tr><th>Name<th>Size<th>Last Modified';
echo '<tbody>';
foreach ($files as $f)
{
    $base = basename($f);
    $size = number_format(filesize($f));
    $date = date($dateformat, filemtime($f));

    echo "<tr><td><a href=\"$base\">$base</a><td>$size bytes<td>$date";

}
echo '</table>';
?>
</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/199305-i-need-to-exclude-files-and-directories/
Share on other sites

One way, create an array of "Excluded directories" and an array of "excluded files" then use the in_array function before printing or assigning them to anything, if they are NOT in the excluded array, print / assign them. If they are continue onward and do not process them.

One way, create an array of "Excluded directories" and an array of "excluded files" then use the in_array function before printing or assigning them to anything, if they are NOT in the excluded array, print / assign them. If they are continue onward and do not process them.

I appreciate the fast response, I'll get on it :).

 

Thank you!

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.