Results 1 to 5 of 5

Thread: Playing images in a folder with different pages?

  1. #1
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Playing images in a folder with different pages?

    Hi all.

    Is it possible to do this:
    Have a folder setup, for example, /img/r1/
    Within that folder will be images in consecutive order.

    Then, in my php file, to read those images and display then in a slideshow. However, I will have different php files with different images. For example, I have www.site.com/hey?id=1, is it possible to use this id= and then tell the script to read images from the /r1/ folder, and if I have a page www.site.com/hey?id=5, the script will read images from /r5/ folder?

    Thanks.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Of course - you can use the query parameter to specify which folder you want. For security reasons, you should have a a list of allowed folders rather than just allowing any path to be specified.

    PHP Code:
    <?php
    $allowedFolders 
    =array( 'r1','r2','r5' );

    if( 
        !empty( 
    $_GET['id'] ) // if the folder I'd is specified
        
    && in_array$_GET['id'],$allowedFolders // and folder is allowed
    ){
        
    /* get photos */
    }else{
        
    /* do default action (e.g., maybe a menu or something) */
    }

  3. #3
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    thanks for the reply. I will try this out soon. For the if part " /* get photos */", does that mean to implement a code such as jquery to put in a slideshow?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There's a PHP slideshow here that has some code that might help you. You can also use a generic code for looping through a folder and grabbing all image files. The exact setup may depend on your system, although it will be simplest if you only have images in the folder and you want to display all of those images. Then you'll just add them using the filepath.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 517 Times in 503 Posts
    Blog Entries
    5

    Default

    Right - to answer you question specifically, no, not jQuery. PHP works on the server, javascript works on the client (browser). They don't know about each other. With this approach, you'd need to get those files using PHP.

    Edit:

    I was looking for the PHP photo album script Daniel mentioned, and I found it, but it's horribly old and uses depreciated (removed in recent PHP versions) functions.

    You might use something like this to get all of the images in a particular folder (untested, I haven't used glob() recently - I'll let you know later if I find problems):
    PHP Code:
    <?php
    $allowedFolders 
    =array( 'r1','r2','r5' );

    if( 
        !empty( 
    $_GET['id'] ) // if the folder I'd is specified
        
    && in_array$_GET['id'],$allowedFolders // and folder is allowed
    ){
        
    /* get photos */
        
    $dir $_SERVER['DOCUMENT_ROOT']."path/to/images/{$_GET['id']}/";
        foreach( 
    glob$dir.'*.jpg',GLOB_MARK ) as $jpgImage ){
            
    $imgTags[] = "<img src="/path/to/images/'. $_GET['id'] .'/'. $jpgImage .'" alt="a slideshow image">';'
        }
        // now 
    $imgTags is an array of <img> elements that you can print out
    }else{
        /* do default action (e.g., maybe a menu or something) */
    }
    Last edited by traq; 11-26-2012 at 02:12 PM.

Similar Threads

  1. SWF Files playing simultaneously after rolling over images
    By graphixdesignz in forum Bug reports
    Replies: 2
    Last Post: 08-06-2011, 02:59 AM
  2. Keep music playing on all pages?
    By kairick in forum HTML
    Replies: 13
    Last Post: 04-06-2010, 04:20 AM
  3. how to pull images from a folder for a slideshow
    By rharris07 in forum Looking for such a script or service
    Replies: 5
    Last Post: 11-16-2009, 11:05 PM
  4. Adding images to a zip folder
    By jc_gmk in forum Graphics
    Replies: 5
    Last Post: 01-25-2008, 09:55 PM
  5. Blocking the /images/ folder?
    By Chris P. Bacon in forum Other
    Replies: 5
    Last Post: 04-21-2007, 10:54 AM

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
  •