Solved

Enabling user to choose image from webserver folder to display

Posted on 2014-11-15
4
194 Views
Last Modified: 2014-11-16
I have a large number of archived images in a public folder on the web server. I want the user to be able to browse a list of the image files by filename and select one to be displayed.  This needs to be done using client-side JavaScript code only (no server-side code).

Basically I want to be able to populate a SELECT tag with the filenames of all files in the webserver folder.

What is the easiest way to do this?

Thanks
0
Comment
Question by:NAKBrooks
  • 2
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 40445089
The client can not access the server's files. Just imagine the havoc if any javascript could read any server. If you want to publish that sort of information, you would have to use a server-side script. For example, in php, you could do this

<select name="picture">
<?php
$files1 = scandir("/usr/local/files/pictures/");
foreach ($files1 as $f)
   print "<option value='$f'>$f</option>\n";
?>
</select>
0
 

Author Comment

by:NAKBrooks
ID: 40445376
Thanks, I understand the security concerns but was assuming that as I can browse the folder concerned by putting the URL in the web browser (it is in a public area of the web site) it should be possible to read the contents of the index somehow and parse it to get an array of filenames using only client-side code.  If not I'll have to try and get php enabled on the server.
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 40445672
You might be able to do it if you are running apache and you have autoindex turned on. What happens when you browse to the directory that contains the images?
0
 

Author Comment

by:NAKBrooks
ID: 40445716
It displays the directory. I think I can get php enabled so I'll accept your php snippet as a solution and build on that. Thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now