简体   繁体   中英

Php access folder from file

I want to access a folder from a .php file using scandir(); !

This is my folder tree:

- public_html:
     - lua:
          - fld1:
               - myfile.php
               - works(folder)

The "fld1" directory contains the php file and the "works" folder(the requested one)

The php file and the folder are in the same location!

I tried to access it like this:

<?php
$dir = "works/";

// Sort in ascending order - this is default
$a = scandir($dir);

// Sort in descending order
$b = scandir($dir,1);

print_r($a);
?>

But nothing is printed on the page!

I also tried this:

$dir = "/works/";

or the full path:

$dir = "/public_html/lua/fld1/works/";

Give the path correctly

Try this:

$dir    = '/works';

or

$dir    = './works';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM