/    Sign up×
Community /Pin to ProfileBookmark

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>
[/CODE]

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledOct 26.2008 — 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.
Copy linkTweet thisAlerts:
@Xtrme_XJauthorOct 26.2008 — how can I do this to get the file names into JS so that they can be used?
Copy linkTweet thisAlerts:
@ZeroKilledOct 26.2008 — 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...
Copy linkTweet thisAlerts:
@rnd_meOct 26.2008 — 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.
Copy linkTweet thisAlerts:
@felgallOct 26.2008 — 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.
×

Success!

Help @Xtrme_XJ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...