Reputation: 78
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
Upvotes: 0
Views: 254
Reputation: 94
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>';
Upvotes: 1
Reputation: 162
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
Upvotes: 2