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

Thread: Easy php help

  1. #1
    Join Date
    Sep 2008
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Easy php help

    Hey all so what I want to do is basically write a php code that pulls all my images from a certain folder filled with images and display them. Can someone write me a simple code that does that?

    Thanks,
    John

  2. #2
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    PHP Code:
    <?php
    $files 
    glob("images/*.*");
    for (
    $i=1$i<count($files); $i++)
    {
        
    $num $files[$i];
        echo 
    '<img src="'.$num.'" alt="random image">'."&nbsp;&nbsp;";
        }
    ?>

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

    jzhang1013 (04-16-2009)

  4. #3
    Join Date
    Sep 2008
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    hey thanks! now where in that code would I specify the folder name? or does this code have to be put in the same folder as the images its grabbing?

  5. #4
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by jzhang1013 View Post
    hey thanks! now where in that code would I specify the folder name? or does this code have to be put in the same folder as the images its grabbing?
    In the second line
    PHP Code:
    $files glob("images/*.*"); 
    I am asuming your the image folder is titled "images", therefore if it is really titled "gobbeldygoop" the second line would be as so:
    PHP Code:
    $files glob("gobbeldygoop/*.*"); 
    Best Regards
    ~Ross

  6. #5
    Join Date
    Sep 2008
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    ok so it supports the basics such as .jpg and .png? and itll just display how i style it correct? Thanks so far Ross!

  7. #6
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    It will display all format images compatable with the browsers. ie: I'am not sure but adobe illiustrator images can be displayed on a webpage when using Firefox but I'am not sure.

    But generally speaking to cover 98% of web browsers, this script will display .JPG, .GIF, .PNG and .BMP files

    EDIT: I just tested the script and discovered that it will only display images DIRECTLY in the folder specified by the script. It will not display any images in subfolders.

  8. #7
    Join Date
    Sep 2008
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    so i tried it and im getting this error..

    Parse error: syntax error, unexpected ';' in /home/jzhang/public_html/testgrab/testgrab.php on line 3

  9. #8
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Make sure you have copied it exactly as I have written, the absolute only thing that you need to change is the foldername betwen the quotation markes on line two. An error msg like that usually indicates a typo from either typing it in by hand too fast or maybe you messed something up when you altered the folder name in line 2

  10. #9
    Join Date
    Sep 2008
    Posts
    77
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    do i have to rename my images to 1, 2, 3, etc?

  11. #10
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    No, this will just go through all the files that the glob() function finds by using count(). It just uses $i as an index so it can go through a loop looking for each file.

    You can name the files whatever you want.

    If you wanted to make it more specific, for example if you have some files in the images folder that aren't images then you could put, for example:
    PHP Code:
    glob("images/*.jpg"); 

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
  •