www.webdeveloper.com
Results 1 to 6 of 6

Thread: read File names

  1. #1
    Join Date
    Sep 2008
    Location
    Harrisonburg, VA
    Posts
    151

    read File names

    I am trying to write something that gets all the images in a single folder and then puts them into an array so that on my web page they can randomly be up there.

    Code:
    	<script type="text/javascript">
            var myPics = new Array();
            myPics[0] = "pics/cup.jpg";
            myPics[1] = "pics/championship.jpg";
            
        var randomnumber=Math.floor(Math.random()*2)
        </script>
    As you can see right now I am putting the image names in hard coded but when I give this to the client I would like for them to be able to just upload pictures to the folder without having to go in and change the JS

  2. #2
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    not with javascript. you will need help from a server side language. first, javascript is client-side, and second javascript don't have support for file system.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  3. #3
    Join Date
    Sep 2008
    Location
    Harrisonburg, VA
    Posts
    151
    how can I do this to get the file names into JS so that they can be used?

  4. #4
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    sorry, can't help with the topic. i'm not experienced with server side language. ask in sever-side development forum. i'm sure guys there will help you, or hopefully someone here will tell you. my apologies...
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    if you don't have an index page in a folder, but rather it shows a directory listing, you can load the folder URL in ajax, rake out the anchor tags that point to images, and build your array from that info.

    in that case, you don't need any server-side code.

  6. #6
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    You can use a server side language such as PHP to generate the JavaScript. The PHP would read the list of filenames of the images from the directory and output the JavaScript code to build the array of those names.
    Stephen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles