Click to See Complete Forum and Search --> : is_dir not working properly


aaronbdavis
07-02-2006, 10:02 AM
I am modifying my WAMP installation in order to use my home PC as a development machine. Normally, the index.php file provided by WAMP will look at all the subdirectories of the doc root and list them under the heading "Your Projects." I use most of the those sub-directories for general purpose development, not for a particular site. Therefore I created another sub-directory called sites, and modified index.php to list all of its
sub-directories under the heading "Sites." The code provided uses the is_dir function so that it only shows directories, not files. However, for some reason, this does not work for my projects folder. I thought it might be because the folder was named /sites/thebaseballwanderer.local (thinking that it might think local was the extension) but when I changed the name, it still did not work. Now, when I comments out the check if the file is a directory, the script works fine, but I am curious why it didn't work like it should.

FYI:
Here is my file structure:

C:/wamp/www
bin
pear
...
sites
thebaseballwanderer.local

...


Here is the relevent section of the original script provided by WAMP
<h1><?php echo $langues[$langue]['txt_projet']; ?></h1>
<div class="content">
<?php
// Affichage de la liste des dossiers non énumérés plus haut ( = projets ).
$list_ignore = array ('.','..','exemples','phpmyadmin','sqlitemanager', 'sites');
$handle=opendir(".");

$msg = $langues[$langue]['txt_no_projet'];
while ($file = readdir($handle)) {
if (is_dir($file) && !in_array($file,$list_ignore)) {
$msg = '';
echo '<a class="ditem" href="'.$file.'"><img src="dossier.gif" alt="image dossier" /> '.$file.'</a>';
}
}
closedir($handle);
echo $msg;
?>
</div>
Here is my modified version<h1>Sites</h1>
<div class="content">
<?php
$handle = opendir("sites");
while ($file = readdir($handle)) {
if (/*is_dir($file) && */!in_array($file, array('.','..'))) {

echo '<a class="ditem" href="http://'.preg_replace('/.com|.net|.org/','.local',$file).'"><img src="dossier.gif" alt="image dossier" /> '.$file.'</a>';
}
}
?>
</div>

bokeh
07-02-2006, 10:20 AM
You really should be using apache and create a virtual host for each new site whether it is local or not. This is not the job of php.

aaronbdavis
07-02-2006, 10:38 AM
I know that. And I am not trying to use PHP to do anything like that. I have already made a virtual host block for localhost and thebaseballwanderer.local, and I have made the corresponding entries to my hosts file.

All I am trying to do now is modify the switchboard to my tastes, in this case, add a link to other hosts on my machine to the main page.

bokeh
07-02-2006, 10:41 AM
modify the switchboardWhat's that, some GUI interface?

aaronbdavis
07-02-2006, 10:49 AM
switchboard is a commonly used name for the central portion of the GUI. It is especially used in MS Access applications, but I think it can be used here as well.

bokeh
07-03-2006, 03:17 AM
All you need is one dynamic virtual host. This will forward each request to its corresponding directory.