Jump to content

List all files in dir, then put content of files into array


mikk809h

Recommended Posts

Hello

 

 

I have a simple question about file handling...

 

 

Is it possible to list all files in directories / subdirectories, and then read ALL files in those dirs,

and put the content of their file into an array?

 

Like this:

 

array:
[SomePath/test.php] = "All In this php file is being read by a new smart function!";
[SomePath/Weird/hello.txt = "Hello world. This is me and im just trying to get some help!";
and so on, until no further files exists in that rootdir.

 

All my attempts went totally crazy and none of them works... therefore i need to ask you for help.

 

 

Do you have any ideas how to do this?

If so, how can I be able to do it?

 

 

Thanks in Advance, pros

Heres my code...

 

Read comments on right side.

 

  Reveal hidden contents

 

 

Thats my code... ( of course without passwords and all that stuffz.. )

 

 

I have no idea why this part doesnt work as i wanted.

 

          foreach($fileinfos as $pathname => $fileinfo) {
            if (!$fileinfo->isFile()) continue;
            $realPath = $uploadsPath . $SessionCount . "/" . $pathname;
            $filee = fopen( $realPath, "r" ) or die("FAILED TO READ FILE!");
            $content = fread($filee,filesize($realPath));
            fclose($filee);
            $AllFiles[$pathname] = $content; #This was to put the filepath ( full path ) and the content of the file into the array..
            var_dump($pathname);          # But it didnt seem to work.
          }
I hope this helps a bit

 

 

Thanks

EDIT:

 

I actually found the solution to the file listening...

 

But i dont think it works very well...

For example I have a file called test.lua in System/Apis/test.lua

The array noticed that as [uploads/1] => "Uploads/1";

 

 

Why?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.