Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    Web Image Gallery Help

    I would like a code that i can stick into my webpage, and it will take every image from a directory and automatically stick them into a page.

    So lets say my directory includes:

    ab.jpg
    rig.gif
    haha.png
    dude.jpg
    mwahaha.jpeg

    it will transfer them into a page with source like this:

    <img src="directory/ab.jpg" alt="">
    <img src="directory/rig.gif" alt="">
    <img src="directory/haha.png" alt="">
    <img src="directory/dude.jpg" alt="">
    <img src="directory/mwahaha.jpeg" alt="">

    Here is the specific directory:
    http://www.lonelylizard.com/~eli/files/gallery/

    Also if in that directory i move some of the images into another subdirectory, lets say:

    http://www.lonelylizard.com/~eli/files/gallery/sigs/
    then i have like 20 images in there, it will stick them into a certain page. This needs to add them when i add the images to the server.

    I am willing to use any language. If someone can code this for me and give me the code that would be awsome.

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This should work, haven't tested though (in PHP), you may need to play around with the name of the directory to get it to work properly.

    PHP Code:
    <?php

    $imgdir 
    './files/gallery/';
    $allowed_types = array('png','jpg','jpeg','gif');

    $dimg opendir($imgdir);
    while(
    $imgfile readdir($dimg))
    {
     if(
    in_array(strtolower(substr($imgfile,-3)),$allowed_types))
     {
      
    $a_img[] = $imgfile;
      
    sort($a_img);
      
    reset ($a_img);
     } 
    }

    $totimg count($a_img);
     
    for(
    $x=0$x $totimg$x++)
    {
     echo 
    '<img src="'.$a_img[$x].'" alt=""><br>';
    }

    ?>

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    how do use this? i haven't use php before?

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #6
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *bump*

  • #7
    Regular Coder
    Join Date
    Jul 2005
    Location
    Halifax, Nova Scotia, Canada
    Posts
    392
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Did you change the value of $imgdir or whatever to what it actually is on your server?

    If so... make this:
    Code:
    echo '<img src="'.$a_img[$x].'" alt=""><br>';
    into this:
    Code:
    echo '<img src=".$imgdir.'$a_img[$x].'" alt=""><br>';
    Make sure $imgdir is initialized near the top of the screen as 'public_ftp/images/' or whatever your image directory is. Try that, haven't tested but I think that should be it.
    Once I thought I was wrong but I was mistaken.


  •  

    Posting Permissions

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