First, about me and what I'm running.
I am fairly new to PHP, but not new to programming. I am doing this on a Mac running OS X Panther, Apache 1.3.33, PHP 5.1.2.
Second the code.
<?php
$dir = '.'; // Current directory
$list = '';
$dircont = scandir($dir); // Scan directory for dir-contents
foreach($dircont AS $item ) // Check each item in $dircont
if(is_file($item) && $item[0]!='.')
$list .= '<a href="'.$item.'">'.$item.'</a>'."<br />\n";
echo $list; // Display the list
?>
Third the problem.
The code above is supposed to list all files within the directory the file is located in. I am having a hard time getting the above code to work for a subdirectory. By assigning '.' to $dir I am successful in getting the files under the current directory my index.php is in to display, but I want it to list all the files in a subdirectory called php that I have put all my php work in.
So far I have tried many different combinations but the errors have fallen between these two things.
$dir = './php/';
results in the main directory's files being displayed, when I would have thought it would create an error.
$dir = 'http://localhost/~username/php/';
results in the following error-
Warning: scandir(http://localhost/~username/php/) [function.scandir]: failed to open dir: not implemented in /Users/username/Sites/index.php on line 17
Warning: scandir() [function.scandir]: (errno 22): Unknown error: 0 in /Users/username/Sites/index.php on line 17
Warning: Invalid argument supplied for foreach() in /Users/username/Sites/index.php on line 18
I am figuring that I either do not know how to assign a path correctly to a variable or I do not understand how to give scandir() what it needs.
Thank you for any and all replies.
Babelosopher