Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Swiss Army Slide Show - skip missing images?

  1. #1
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Swiss Army Slide Show - skip missing images?

    1) Script Title: Swiss Army Slide Show

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...army/index.htm

    3) Describe problem:
    I have a series of slide shows on different pages, with up to 20 images on each show. I'm wondering if there is a way to make the script skip missing images if they are not all there, and just continue on to the next one.

    Thanks,
    steamfreak

  2. #2
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm replying to my own post here...

    I found a way around my problem. Instead of hardcoding the
    slides[0] = ["slide1.jpg", ""];
    slides[1] = ["slide2.jpg", ""];
    :
    :
    entries, I wrote a simple php script to generate this based on the contents of the folder where the images are stored. Now I can store images of any name and any number of them and it should work.

    Cheers,
    steamfreak.

  3. #3
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Do you mind sharing your php script, please?

    Thanks

  4. #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

    My PHP is not the best, but you can do something like so on most PHP servers (filename - get_slides.php):

    PHP Code:
    <?php header('Content-Type: text/javascript');
    function 
    returnimages($dirname="./images/") {
       
    $pattern="\.(jpg|jpeg|png|gif|bmp)$";
       
    $files = array();
       
    $curimage=0;
       if(
    $handle opendir($dirname)) {
           while(
    false !== ($file readdir($handle))){
                   if(
    eregi($pattern$file)){
                     echo 
    'slides[' $curimage .']=["' $dirname $file '", "", ""];' "\n";
                     
    $curimage++;
                   }
           }

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

    echo 
    "var slides=new Array();" "\n";
    returnimages();
    ?>
    That will pick up the images in a folder called images of off the folder in which the above file is located, and define them as elements in the slides array. Then on a regular HTML or PHP page in the same folder as get_slides.php (not in the images folder), instead of defining the slides array in your code, link first to the external script:

    HTML Code:
    <script type="text/javascript" src="get_slides.php"></script>
    Remember not to redefine the array named slides on your page or in other scripts linked to it.
    - John
    ________________________

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

  5. #5
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Would you please give me a good link where I can find very basic info on how to use a php file like yours, without wasting your time for that?

    Thanks.

  6. #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

    I'm not sure I understand your question. To use it you just save it in a text editor as:

    get_slides.php

    Upload it to a PHP enabled server. Put your page with swiss army on it in the same folder but don't define the slides array, and place this in the head:

    HTML Code:
    <script type="text/javascript" src="get_slides.php"></script>
    before any of the swiss army script code.

    Put your images in a folder named:

    images

    off of the folder that contains the above files.

    Also, if you want to get a better idea of the principals involved, you should have a look at this script:

    http://www.dynamicdrive.com/dynamici...photoalbum.htm

    it uses a similar sort of separate PHP file as an external javascript to gather the image names from a folder. The main differences are the name of the array generated and the purposes it is put to in the main script.

    If on the other hand you want to learn how to code in PHP, I like this site:

    http://us.php.net/manual/en/index.php

    But I'm no PHP expert, not even all that experienced. There could be better resources out there.
    Last edited by jscheuer1; 11-26-2007 at 07:39 AM. Reason: clarity
    - John
    ________________________

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

  7. #7
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I asked my web provider and they said the hosting of my site is not PHP enabled. I could buy the PHP + MySQL enabling for 250 euro a year: is there anything else I can do about it?

    Should I be interested in this script all the same, will I have to install anything on my PC to make it work at least locally?
    If yes (as I think), which interpreter/compiler would be better? (Win2k or XP)

    Thanks and sorry for the dumb questions.

  8. #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

    There are some free hosts that support PHP, perhaps some even with MySQL support as well. You don't need MySQL (a popular data base program) for this code.

    There are PHP and server emulators for local windows machines, that should allow (some of these emulations are, as I understand it, far from perfect) you to test your PHP code locally. More than one program may be required, at least for certain implementations. I have no experience with any of them, so cannot make any recommendations, or even speak with any real authority about any of that.

    When testing (I do so little of this sort of coding anyway), I just upload to a PHP enabled server and see what happens.
    - John
    ________________________

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

  9. #9
    Join Date
    Nov 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks to your answer, as usual.

    After some thinking, I realized I don't really need a PHP script because my only need is to automatically build the array, pointing to a folder, locally.
    Then I will upload the files to my hosting service.
    I will rarely, if ever, change the folder content and if I will, I'll be happy to run the "array building" local script again to update the array.
    Trouble is: how to make this script? Or: is there such a script not involving a specific server side service?

    Thanks.

  10. #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

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
  •