Hello. I found a template with a php script that reads the files folder in the root of the site.

The site is on my path /var/www/web/ , that is, the script reads only the folder /var/www/web/files . How to rewrite the path in the script so that it can scan files from the /Z/FTP/ folder?

Here is the script itself and where did I get the template from if anyone is interested in http://tutorialzine.com/2014/09/cute-file-browser-jquery-ajax-php/

 <?php $dir = "files"; // Run the recursive function $response = scan($dir); // This function scans the files folder recursively, and builds a large array function scan($dir){ $files = array(); // Is there actually such a folder/file? if(file_exists($dir)){ foreach(scandir($dir) as $f) { if(!$f || $f[0] == '.') { continue; // Ignore hidden files } if(is_dir($dir . '/' . $f)) { // The path is a folder $files[] = array( "name" => $f, "type" => "folder", "path" => $dir . '/' . $f, "items" => scan($dir . '/' . $f) // Recursively get the contents of the folder ); } else { // It is a file $files[] = array( "name" => $f, "type" => "file", "path" => $dir . '/' . $f, "size" => filesize($dir . '/' . $f) // Gets the size of this file ); } } } return $files; } // Output the directory listing as JSON header('Content-type: application/json'); echo json_encode(array( "name" => "files", "type" => "folder", "path" => $dir, "items" => $response )); 
  • what a strange question, are you new? $ dir = $ GET ['dir']; dir is a variable containing the path to the directory, and you also need to configure the server to access the necessary directories - OlegUP
  • Yes, I have never worked with php. $ dir = $ GET ['dir'] doesn't work like this. And if you do this $ dir = "/ Z / FTP /"; That file does not display, but file search works. - Kleimosc
  • Do you only need this directory? What server response code is coming? perhaps just a group of users do not have permissions to read this directory, here it is necessary to open read permissions in the OS and on the server - OlegUP
  • and yes it’s right to write $ _GET, I haven’t touched three php for a year already. read how to work with it if you need not only this directory - OlegUP
  • rights to the folder are on "Z" dr-xr-xr-x 11 nobody nogroup on "FTP" "drwxrwxrwx 10 nobody nogroup - Kleimosc

1 answer 1

Probably should change the third line with

 $dir = "files"; 

on

 $dir = "/Z/FTP"; 

and the fifth bottom line with

 "name" => "files", 

on

 "name" => "FTP",