www.webdeveloper.com
Results 1 to 6 of 6

Thread: self populating slideshow (php)

  1. #1
    Join Date
    Jun 2013
    Posts
    12

    self populating slideshow (php)

    Hello. I have been looking for either plugins or a tutorial for creating a self populating dynamic slideshow (from a specified folder). At first I was looking for a specific one, but soon started looking for one without any specs (as I thought I should deal with knowing how to create a self populating dynamic slideshow first, being my priority).

  2. #2
    Join Date
    May 2007
    Location
    Ferndale WA
    Posts
    11

  3. #3
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    with that code snippet if you wanted to add multiple file extentions how would u add them?

    .jpg | .png something like that???? considering your example

    Code:
     <?php
    //path to directory to scan. i have included a wildcard for a subdirectory
    $directory = "images/*/";
     
    //get all image files with a .jpg extension.
    $images = glob("" . $directory . "*.jpg");
     
    $imgs = '';
    // create array
    foreach($images as $image){ $imgs[] = "$image"; }
     
    //shuffle array
    shuffle($imgs);
     
    //select first 20 images in randomized array
    $imgs = array_slice($imgs, 0, 20);
     
    //display images
    foreach ($imgs as $img) {
        echo "<img src='$img' /> ";
    }
    ?>

  4. #4
    Join Date
    Jun 2013
    Posts
    12
    Yes it is exactly what I was looking for. Thank you very much. Although there is one line of code which I do not understand at all:
    PHP Code:
    foreach($images as $image){ $imgs[] = "$image"; } 
    Why does the author of the snippet use the $images as $image? Aside from that line of coding, he never uses the variable image anywhere except there.


    As for for Diaz is saying, I will look into that

  5. #5
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    hes creating an array. saying that all of the images become image and imgs = image

    then he is saying take the imgs which is all of the images all together and slice them which is the last array made which allows to separate them back to just one. $img which he calls in the last statement

    $img

  6. #6
    Join Date
    Jun 2013
    Posts
    12
    Thanks for the reply and what you said concerning the $img.
    Sorry for the late one on my part.

    I've been working with it but I am running into a brick wall. I am trying to set up a dynamically auto-populating slideshow. But I don't understand what's wrong with my code. I know that both codes work separetly - I tested them out. One of the codes works with non-dynamic related directory. As for the dynamic aspect, I tried it out (without any CSS or anything else, and all pictures from the folder appears).

    I know there must be a problem with how I'm coding it, but I can't put my finger on what I'm doing wrong.
    The code I have is the following:

    <?php
    //path to directory to scan.
    $directory = "images/";

    //get all image files with a .jpg extension.
    $images = glob("" . $directory . "*.jpg");

    $imgs = '';
    // create array
    foreach($images as $image){ $imgs[] = "$image"; }

    //shuffle array
    shuffle($imgs);

    //select first 20 images in randomized array
    $imgs = array_slice($imgs, 0, 20);
    ?>



    <script type="text/javascript" language="javascript">
    $(document).ready(function() {
    $(".box_skitter_large").skitter();
    });
    </script>



    <div class="box_skitter box_skitter_large">
    <ul>
    <li>

    <?php
    //display images
    foreach ($imgs as $img) {
    echo "<img src='$img' />";
    }
    ?>


    </li>
    </ul>


    </div>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles