Can someone explain why this code does not work for the mac. This script works great on my site (can see here http://wattsupnow.com/dlist.php). Any help would be great!!!
<?php
// get current Directory
$myDir = getcwd() ;
//print directory path
echo $myDir;
// open directory and read all files
if ($handleDir = opendir($myDir)) {
// zero out counter
$i = 0;
//loop through all files in directory
while ($myfilenames = readdir($handleDir)) {
// add all files to an array
$myArray[$i] = $myfilenames;
// increase array element
$i;
// count total files in array
$arrayLength = count($myArray);
// loop through and print each element assign to array
for ($i = 0; $i < $arrayLength; $i){
// print each element
echo "myArray at" . $i . " is: " .$myArray[$i] . "<br>n";
}
// close current direct
closedir($handleDir);
}
// end script
?>
Page 1 of 1
PHP getting filelist of current directory
#2
Posted 14 September 2006 - 06:25 PM
Your problem mostly has to do with the curly braces in the wrong place. I've cleaned up and fixed your issues and here's the result:
Code:
Code:
<?php
$myDir = getcwd();
if ($handleDir = opendir($myDir))
{
while ($myfilenames = readdir($handleDir)) // loop through all files in $myDir
$myArray[] = $myfilenames; // add all file to $myArray
$arrayLength = count($myArray); // count total files in $myArray
$i = 0;
foreach ($myArray as $file )
echo "myArray at" . $i . " is: " . $file . "<br />" . "n"; // print each $file in $myArray
closedir($handleDir); // close $myDir
}
?>
Page 1 of 1



Sign In
Register
Help


MultiQuote