Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Building a dynamic array from folder contents

  1. #1
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Building a dynamic array from folder contents

    I'm using a couple of different slide show scripts. Both use arrays to define the graphics to be displayed. The problem is that I have a large graphics library and I'd like to put the graphics for the slide show scripts in separate folders and then have the arrays built dynamically based on the contents of the folder regardless of the filename or extension. I also want to change the graphics now and then and it would be easier to just move the new graphics into the folder instead of having to change all the array definitions.

    Does anyone have a script that will do that or could someone suggest how that can be done in javascript? Any help would be appreciated.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If you wouldn't mind this only working on the server, and you have a server side language available to you, see:

    http://www.dynamicdrive.com/forums/s...ad.php?t=29378
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Jim Weinberg (05-06-2008)

  4. #3
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    John.

    Thanks for the reply.

    I've checked out the link you mentioned. Unfortunately, I can't use .asp (not supported) and I don't know .php. I really need a javascript solution.

    Jim

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    We can talk you through the PHP part if your server supports PHP. I don't think there is any client side (javascript) solution that will fit your requirements.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    John.

    Again, thank you for your response.

    I'm on a Linux server, so I don't know if PHP is supported or not. The problem is that I have close to 50 pages on my website and this would be the only PHP code.

    I hope you don't take offense, but I think I'm going to post my problem on a couple of other forums and see if someone has a javascript solution.

    Best regards,
    Jim

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It would take more than that to offend me. Um, virtually any server can have PHP. It is more common on non-Windows servers, but can be run on just about anything. I wasn't suggesting that you install PHP on your server. That would be beyond me, though there are probably a few folks around here that could help with that. I had gotten the impression that your server had PHP already. If it does, PHP is the simplest and best solution.

    I did a Google on how this might be done via javascript alone and cane up with a IE only method using Active X. But that would really limit the usefulness of the code. And, I believe that would only run in conjunction with a Windows OS anyway, perhaps even only for files on the localhost.

    Now, as I mentioned before, javascript can work out if you know the number of images, and there is a base filename for the images. Like if you have 10 files and name them:

    slide_0.jpg
    slide_1.jpg
    slide_2.jpg

    and so on. Each time you added one, you would give it the next name in line and increase the number in the the script that sets the upper limit on the number of images to look for.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #7
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Red face

    John.

    Well, it's been 4 days and I must conceed that there is apparently no javascript solution.

    I've downloaded the PHP script you mentioned and if your offer still stands would like to take you up on walking me through the code.

    Jim.

  9. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Jim Weinberg View Post
    John.

    Well, it's been 4 days and I must conceed that there is apparently no javascript solution.

    I've downloaded the PHP script you mentioned and if your offer still stands would like to take you up on walking me through the code.

    Jim.
    OK, just go over the thread:

    http://www.dynamicdrive.com/forums/s...ad.php?t=29378

    particularly the parts that refer to PHP. It really isn't as complex as you might think. If you do have a problem, let me know. Things that will help me help you at that point are, if you:

    1. Post a link to the page on your site where you are trying this.
    2. Post a copy of the exact getpics.php file you are using.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #9
    Join Date
    Jan 2006
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    John.

    I have so many questions, I'm not sure where to start. So let me start here:

    The call line for the slideshow is:

    <script>new fadeshow(ShowPics, 295, 210, 3, 3000, 1)</script>

    The page header is as follows:

    <script type="text/javascript" src="Script_Files/getpics.php"></script>
    <script type="text/javascript" src="Script_Files/slideshow.js"></script>
    <script type="text/javascript">
    var fadearray=new Array() //array to cache fadeshow instances
    var fadeclear=new Array() //array to cache corresponding clearinterval pointers
    var fadebgcolor="#FEF4E4"
    var display_height="50%"
    var caption_size=2
    </script>



    The php file looks like this:

    <?php
    Header("content-type: application/x-javascript");

    function returnimages($dirname="./") {
    $pattern="\.(jpg|jpeg|png|gif|bmp)$";
    $files = array();
    $curimage=0;
    if($handle = opendir($dirname)) {
    while(false !== ($file = readdir($handle))){
    if(eregi($pattern, $file)){
    $filedate=date ("M d, Y H:i:s", filemtime($file));
    echo 'ShowPics[' . $curimage .']=["' . $file . '", ""];' . "\n";
    $curimage++;
    }
    }

    closedir($handle);
    }
    return($files);
    }

    echo "var ShowPics=new Array();" . "\n";
    returnimages();
    ?>

    The first problem is that my pages are in one folder, the scripts are in another (called Script_Files) and the pictures are in a third (Graphics/ShowPics). I want to maintain this organization. Ideally, I would like to pass the picture path to the script so I don't have to change the code each time.

    Second, I want to link the pictures to a larger view, but I don't want to have to have 2 copies of each picture. The "display_height" variable, above, controls the initial slide show size (I modified the fadeshow script to accomodate this).

    The third is that I've also modified the fadeshow script slightly to accomodate captions, so the fadeshow script needs to have 4 parameters passed to it. If I were to use an array to define the pictures, it would look like this:

    ShowPics[0]=["Graphics/ShowPics/judging.jpg", "Graphics/ShowPics/judging.jpg", "new",""]

    The particular slide show I'm working on won't have captions, but I use the script for other slide shows that do.

    I have no idea how to modify the php code to accomodate the above. Can you help?

    Jim

  11. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The getpics.php file should be in the folder with the images in it.

    Once you have that, modify this line:

    PHP Code:
    echo 'ShowPics[' $curimage .']=["' $file '", ""];' "\n"
    to:

    PHP Code:
    echo 'ShowPics[' $curimage .']=["Graphics/ShowPics/' $file '", "Graphics/ShowPics/' $file '", "_new"];' "\n"
    The paths (one path used twice) should be relative to the page that is using the images.

    However, just as an observation on something you say you are doing - Loading up the full sized images in the slide show, unless they are fairly small in byte size will take quite a bit of time. Swiss Army slide show at least would do this incrementally:

    http://www.dynamicdrive.com/dynamici...army/index.htm

    But regardless of which you use, your slide shows will benefit from having optimized images in them that are no larger in either their dimensions or byte size than they need to be for display purposes.

    You could put these 'thumbnails' in a separate directory and name each one the same as its larger counterpart. Then simply put the path to this thumbnail directory in getpics so it will be used for the first entry in the array generation line, ex:

    PHP Code:
    echo 'ShowPics[' $curimage .']=["Graphics/ShowPicsTbn/' $file '", "Graphics/ShowPics/' $file '", "_new"];' "\n"
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •