www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: display images in a folder

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Location
    Parts Unknown......
    Posts
    88

    display images in a folder

    Hi I am trying to display all the images in a certain folder.

    I dont want to display the directory itself of the parent directory.

    I would like to show the actual photos instead of the links also.

    Here is the code:
    PHP Code:
    <?php
    session_start
    ();
    ?><!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
           <title>Easy display</title>
    </head>
    <body>
    <?php

    $dirname 
    "./imagesFolder/user${_SESSION['user']}/";
    $images scandir($dirname);
    foreach(
    $images as $curimg){
      echo 
    "<a href='./imagesFolder/user${_SESSION['user']}/$curimg'>$curimg</a><br>\n";
    }; 
        
    ?>
    </body>
    </html>
    Any suggestions?

    Thanks in advance!

  2. #2
    Join Date
    Mar 2007
    Location
    Nagpur (India)
    Posts
    107
    Use the <IMG> tag instead of Anchor Tag (<A>) for displaying the image, instead of a link.

  3. #3
    Join Date
    Dec 2007
    Location
    Swindon, England.
    Posts
    37
    and you can have an if inside the foreach statement...
    PHP Code:
    $ignore = Array(".""..""otherfiletoignore");
    foreach(
    $images as $curimg){
    if(!
    in_array($curimg$ignore)) {
    echo 
    "<img src='./imagesFolder/user${_SESSION['user']}/$curimg' /><br>\n";
    }; 


  4. #4
    Join Date
    Nov 2007
    Location
    Parts Unknown......
    Posts
    88
    Thanks guys that did the trick!

  5. #5
    Join Date
    Nov 2007
    Location
    Parts Unknown......
    Posts
    88
    I now would like to display the images in a thumbnail. I'm not sure how to proceed with that. I have read something about getimagesize() but I am not sure if this is what I would use or how I would use it in this situation.

    Here is the code:
    PHP Code:
    <?php
    session_start
    ();
    ?><!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
           <title>Easy display</title>
    </head>
    <body>
    <a href="../main.page.php">back to main page</a><br/><br/>
    <?php

    $dirname 
    "./imagesFolder/user${_SESSION['user']}/";
    $images scandir($dirname);
    $ignore = Array(".""..");
    foreach(
    $images as $curimg){
    if(!
    in_array($curimg$ignore)) {
    echo 
    "<img src='./imagesFolder/user${_SESSION['user']}/$curimg' /><br>\n";
    };
    }     
    ?>
    </body>
    </html>
    Any suggestions on how to create thumbnails out of any image in a particular folder?

  6. #6
    Join Date
    Dec 2007
    Location
    Swindon, England.
    Posts
    37
    Do you have the GD Images library installed? Or do you just want to use a new height/width to make the image look smaller?

  7. #7
    Join Date
    Nov 2007
    Location
    Parts Unknown......
    Posts
    88
    I am not sure if I have the GD Library installed but I believe I do. I have done a little research and came up with some code that will change the images in a folder to thumbnails and it requires the GD Library and it appears to work. But I am not sure if this is the best way for me. The problem that I have is that some images will be 1536 x 2048 or 2048 x 1536. I need them to resize no matter which dimension is bigger. I then want to add a radio button or some control that will allow the user to choose a image.

    I am open to any other suggestions.

    Thanks.

  8. #8
    Join Date
    Jan 2008
    Location
    ON CA
    Posts
    58
    Hi,

    This script might be what you're looking for. It looks for images in a directory, creates thumbnails (if it hasn't already) and displays them, making the thumbnails clickable to see the full image. Plus it has features, is easy to configure, and of course you can modify it to suit your needs.

  9. #9
    Join Date
    Nov 2007
    Location
    Parts Unknown......
    Posts
    88
    Thanks for all the ideas but I found a solution to my problem.

  10. #10
    Join Date
    Oct 2011
    Posts
    1

    Smile What solutions?

    HI Graphical Force,

    It would be nice to let us know what solution have you found as others including myself are interested.

    thanks...

  11. #11
    Join Date
    May 2013
    Posts
    2
    this is a php code
    <?
    $files = glob("images/*.*");
    for ($i=0; $i<count($files); $i++)
    {
    $num = $files[$i];
    echo '<img src="'.$num.'" alt="random image" />'."<br><br>";
    }
    ?>

  12. #12
    Join Date
    May 2013
    Posts
    3
    Hi,
    I came across this post and it works excellent, but the images are all loaded in a vertical line.
    1. How do I change this to be Horizontal until page is full and then move to second line.
    2. How do I add in the image name (file name) for each image.

    Using your code below:
    <?php
    $dirname = "pictures/test";
    $images = scandir($dirname);
    $ignore = Array(".", "..", "otherfiletoignore");
    foreach($images as $curimg){
    if(!in_array($curimg, $ignore)) {
    echo "<img src='pictures/test/$curimg' /><br>\n";
    };
    }
    ?>
    Thanks,

  13. #13
    Join Date
    May 2013
    Posts
    2
    Quote Originally Posted by Henry07 View Post
    this is a php code
    <?
    $files = glob("images/*.*");
    for ($i=0; $i<count($files); $i++)
    {
    $num = $files[$i];
    echo '<img src="'.$num.'" alt="random image" />'."<br><br>";
    }
    ?>


    Duplichecker - Plagiarism software

  14. #14
    Join Date
    Dec 2011
    Posts
    163
    echo "<img style="float:right;" src='pictures/test/$curimg' /><br>\n";

    that should do the trick....

  15. #15
    Join Date
    May 2013
    Posts
    3
    Hi,
    Thanks no the images are floating to the right, but not in line.
    See updated scripting and attached image:

    <?php
    $dirname = "pictures/test";
    $images = scandir($dirname);
    $ignore = Array(".", "..", "otherfiletoignore");
    foreach($images as $curimg){
    if(!in_array($curimg, $ignore)) {
    echo "<img style='vertical-align: middle; float: right'; title='$curimg'; src='pictures/test/$curimg'; /><br>\n";
    };
    }
    ?>

Thread Information

Users Browsing this Thread

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

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