1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get all files names in a direcotry

Discussion in 'XenForo Development Discussions' started by Dadparvar, Apr 15, 2016.

  1. Dadparvar

    Dadparvar Well-Known Member

    Hi,

    In my add-on, there is folder, that in it, again there is folder with for each user (folder's name is user's id)

    Now, in a template, there is js code that gets the directory of each user's dedicated folder and then, in an array, gets the name of all files names inside the folder and show them in profile page of user.

    For example: I uploaded 10 files in my own folder. So, the js gets the directory with this code:
    Code:
                this.sources    = {
                    mp3    : 'styles/default/dadparvar/test/files/{$user.user_id}/' + this.name + '.mp3',
                    ogg    : 'styles/default/dadparvar/test/files/{$user.user_id}/' + this.name + '.ogg'
                };
    and in my profile page, in a tab, it shows them using this code (it gets an array):
    Code:
    [ 'song1', 'song2', 'song3', 'songx' ]
    You see I have 4 files uploaded in my own directory.

    Now the question is: how can I get those files names in that structure (array) automatically using js? Now as you see I manually wrote those names.

    Thanks in advance
     
  2. katsulynx

    katsulynx Well-Known Member

    Create a helper that takes the user(-id) as Input. Scan the directory with phps scandir function, pretty-print the data as you need it and return it.
     
    Dadparvar likes this.

Share This Page