Javascript to display all files in a directory on a web server

I know how to do this in server-side languages, but I was wondering if there is an easy way (as without active X). Google search queries give me the ability for javascript to display files from a user computer.

How can I use javascript to display all files on the server. That is, if I have a folder / gallery, and there can be many sub-directors, / gallary / sports, / gallary / california, / gallary / christmas. Each subdirectory contains n images.

How can I get javascript to display all subdirectories as well as all images.

+6
source share
1 answer

Since javascript in the browser cannot directly access the server’s file system, you will probably need some server-side scripts, such as PHP, Perl, ASP, etc., to send the contents of the file system to a web page (possibly via Ajax), and then have the javascript format of the contents of the file system in the desired format, say, using the file tree management in this answer: https://stackoverflow.com/a/9057959/74585

If you cannot use server-side scripts, perhaps you could hard code the categories in the javascript file (assuming the categories change not very often) and the number of images in sequence? Then your javascript can simply search for images, trying to load the folder and image category number. Then determine when the image does not load using onerror and stops displaying the previous / next buttons.

An even more left-handed field solution that does not require server-side scripting may be to create a script, say, with perl, on your workstation that connects via FTP, scans all folders and files and creates a JSON or XML file containing the file contents system. Then your javascript can call this generated file and access the file system. The downside is that you need to restart the script workstation every time you want to add another file.

+2
source

Source: https://habr.com/ru/post/907184/


All Articles