Hey all, my first post :D
Problem:
I'm trying to make a template gallery, not a slide show, which i can easily reuse on multiple sites.
Mostly for quick folio sites, where the owner wont know how to update the code to add pictures.
It needs to read all of the image files from a selected directory. (jpg, gif, png, bmp) It needs to be able to update content without any code changes. (dynamic load from folder) It needs to write out img tags to the viewed page. (using JavaScript for customization/css?)
The set of img tags output from the php/JavaScript need to be thumbnails which when clicked will link to the full def pictures, this can probably be handled with JavaScript when making the links initially.
Progress:
I found a php script that will read the files from a folder and save the urls to an array for use in JavaScript. However the code used to display the picture is done as a single block slide show, where as i need it to post all images separately not just replace the src of the same image.
Example:
root/index.htm - pastebin[.]com/m52568ed5
root/images/getimages.php - pastebin[.]com/f5395a572
root/images/pic01.png
root/images/pic03.jpg
root/images/asdfs.gif
So how do i get JavaScript to loop through the galleryarray[curimg] and write out my links?
I got this far, and got stuck.
function rotateimages(){
// document.getElementById("slideshow").setAttribute("src", "res/gallery/painting/"+galleryarray[curimg])
// curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
for (curimg=1;curimg!=0;curimg++;) {
document.write("<div><img class='gallery' src='" + galleryarray[curimg] + "' /></div>")
}
}
Thanks in advance, Braden.
EDIT: heres my sandbox to show whats going on
-EDIT: removed link
No matter how i change the output per item for example if i replace the whole section with a simple echo all i ever get is the following:
<!DOCTYPE html>
<html>
<head>
<title>My Gallery</title>
</head>
<body>
<div id="gallery"></div>
</body>
</html>
Seems like it gets stuck when it tries to run the 'foreach()'
Heres the current php:
<?php
function getDirTree($dir,$p=true) {
$d = dir($dir);$x=array();
while (false !== ($r = $d->read())) {
if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
$x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
}
}
foreach ($x as $key => $value) {
if (is_dir($dir.$key."/")) {
$x[$key] = getDirTree($dir.$key."/",$p);
}
}
ksort($x);
return $x;
}
$tree = getDirTree("./res/gallery/");
echo '<div id="gallery">';
foreach($tree as $element => $eval) {
if (is_array($eval)) {
foreach($eval as $file => $value) {
if (strstr($file, "jpg")) {
$file = 'res/gallery/'.$element.'/'.$file;
echo 'test'; //test//echo '<a href="'.$file.'">test</a>'; //test// <img class="gallery" src="'.$file.'" alt="'.$file.'"/></a>';
}
}
}
}
echo '</div>';
considering as i have Never done php before i started this, i think im doing ok.