Search code examples
phpfileglob

php doesn't scan relative path for files


Here is my current code (that i am very proud of for my first attempt at php)

<?php
$files = glob("/jobops/*.txt");
$indexcount = count($files);
sort($files);
print("<br>"+$indexcount+"<br>");
foreach ($files as &$file)
{
    print("<a href=\"$file\">$file</a><br>");
}
?>

the problem is glob again works fine in the root directory (where this script is located) but when i point it to a specific folder it returns 0 files found.

I've included a screen grab from my ftp client showing the directory structure (below)

so I'm confused what I'm doing wrong on the glob

www.markonsolutions.com/test.php is where the script is and if you click it will return 0 files found

alt text


Solution

  • "/jobops/*.txt"
    

    is an absolute path on *nix, if you want to point to the directory that is in the same directory as a your php script you need to use:

    "jobops/*.txt"
    

    which is a relative path.