0

I made an image slideshow of sorts for a website. Right now each slideshow image is a list item stored in a unordered list and I use javascript and naming conventions to write each list item out. Example:

for (j = 0; j<imageFileLength; j++){
    $('ul#Slider').append('<li><img src="'+fileName+'/0'+j+'.png" /></li>');} //write list items for each image
 });

This worked for awhile but now I can't hardcode it like this anymore. Anyone needs to be able to drop files into my folder, favorably with any name, and they will automatically be added as a list item to the unordered list.

I am required to use IE 8 which is a bit of a problem. It doesn't support the HTML File API, and it also doesn't support using PHP, but I might be able to get this turned on.

Any ideas? Or, if PHP is a good way to go about it, how it would be done? Maybe java via netbeans?

thank you

emilyn
  • 78
  • 1
  • 11
  • IE 8 supports PHP just fine because it doesn't know that PHP is being used. PHP is on the server side. If done properly, it produces HTML. IE 8 only sees the HTML. Perhaps you meant that you are using Microsoft IIS and you don't have PHP added to that? If you do add PHP, all you are looking for is a simple file list from a directory: http://stackoverflow.com/questions/5694385/getting-the-filenames-of-all-files-in-a-folder – kainaw Jan 28 '15 at 15:07
  • No, PHP is turned off at my workplace but I can possibly get it turned on. – emilyn Jan 28 '15 at 15:09
  • the ability to use php in developementl files is turned off, i guess i should say. i'm not sure what it actually is but i know it's a bunch of security stuff – emilyn Jan 28 '15 at 15:10

2 Answers2

2

Look at http://php.net/manual/en/function.dir.php

in the documentation was the following example, which should set you on the path you're looking for:

<?php
$d = dir("/etc/php5");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();
?>

The above example will output something similar to:

Handle: Resource id #2 Path: /etc/php5 . .. apache cgi cli

trogers1884
  • 172
  • 8
1

Here is the code which is being used and works without any issue.

$folder = 'images/';
$filetype = '*.jpg'; /* use the file extension you would read; here its jpg file */
$files = glob($folder.$filetype);
$count = count($files);
echo '<ul id="slider">';
for ($i = 0; $i < $count; $i++) {
    echo '<li>';
    echo '<img src="'.$files[$i].'" />';
    echo substr($files[$i],strlen($folder),strpos($files[$i], '.')-strlen($folder)); /* display name of the file */
    echo '</li>';
}
echo '</ul>';
Shreyo Gi
  • 94
  • 9
  • for some reason this doesn't work for me. is this just javascript and jquery? i understand how this should work though, and this is awesome. thank you for sharing. – emilyn Jan 28 '15 at 15:39
  • Please accept the code that worked for you. This can be helpful for others too. :) – Shreyo Gi Jan 28 '15 at 18:37
  • none of these actually worked. I actually discovered it's impossible without PHP. I'm trying to get approved to get it turned on. But there's a lot of security issues with PHP. – emilyn Jan 29 '15 at 20:26
  • yes, there are security issues with php but its upto us who develop with the glitches of php in mind. – Shreyo Gi Jan 30 '15 at 02:49