PHP list images in dir

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheMaster
    Confirmed User
    • Nov 2003
    • 2734

    #1

    PHP list images in dir

    can anyone help me out,

    looking for little php script/page that when it's put in a directory it shows all images in that directory (the full image)

    thanks
    I suck at php
  • FlowerKid
    Confirmed User
    • Sep 2005
    • 1045

    #2
    Here is a script i wrote a time ago:
    http://e99.hotarcs.net/temp/index.zip

    You can see it in action here:
    http://e99.hotarcs.net/smilies/

    Hope this is more or less what you are looking for.

    Comment

    • u-Bob
      there's no $$$ in porn
      • Jul 2005
      • 33063

      #3
      Code:
      <?php
      foreach (glob("*.jpg") as $filename) {
      	echo "<img src=\"$filename\"><br><br> \n";
         }
      ?>

      Comment

      • TheMaster
        Confirmed User
        • Nov 2003
        • 2734

        #4
        thanks FlowerKid and u-Bob

        say, have tried 10 possibilities, but still doesn't work, what if I wanted to get the images from one directory down

        eg /joyce.php gets images from /joyce/

        echo "<img src=\"$filename\"><br><br> \n";

        where do I add the dir, nothing seems to work
        really should get a book on php

        Comment

        • TheMaster
          Confirmed User
          • Nov 2003
          • 2734

          #5
          bump bump bump

          Comment

          • Dynamix
            G F Y not
            • Jan 2004
            • 2910

            #6
            This is used in my draft script, hopefully it will help! Change the folder path in the $current_dir= line.

            Code:
            <?PHP
            $current_dir = "Drafts/";
            $dir = opendir($current_dir);
            while ($file = readdir($dir))
            {
            	if (substr($file, 0, 1) != ".") {
            	echo "<IMG SRC='Drafts/" . $file . "' BORDER=0><BR><BR>";
            	}
            }
            closedir($dir);
            ?>

            TGPFactory Full TGP Design & Installation Services
            ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
            See who I am at AdultWhosWho.com!

            Comment

            • Dynamix
              G F Y not
              • Jan 2004
              • 2910

              #7
              Please keep in mind the path is relevant to the script. So for example if your script is located at:
              public_html/scripts/showimages.php

              And you want to display images from:
              public_html/images/photogs/

              You would set your path accordingly:
              $current_dir = "../images/photogs/";

              TGPFactory Full TGP Design & Installation Services
              ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
              See who I am at AdultWhosWho.com!

              Comment

              • TheMaster
                Confirmed User
                • Nov 2003
                • 2734

                #8
                Originally posted by Dynamix
                Please keep in mind the path is relevant to the script. So for example if your script is located at:
                thanks Dynamix, but doesn't seem to work for me, have;

                Code:
                <?PHP
                $current_dir = "models/hegre/";
                $dir = opendir($current_dir);
                while ($file = readdir($dir))
                {
                	if (substr($file, 0, 1) != ".") {
                	echo "<IMG SRC='joyce/" . $file . "' BORDER=0><BR><BR>";
                	}
                }
                closedir($dir);
                ?>
                script is in /models/hegre/, pics in /models/hegre/joyce/
                anyone see my mistake, php makes me feel so dumb

                Comment

                • Dynamix
                  G F Y not
                  • Jan 2004
                  • 2910

                  #9
                  $current_dir = "models/hegre/";

                  should read:

                  $current_dir = "models/hegre/joyrce/";


                  Try that out

                  TGPFactory Full TGP Design & Installation Services
                  ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
                  See who I am at AdultWhosWho.com!

                  Comment

                  • Dynamix
                    G F Y not
                    • Jan 2004
                    • 2910

                    #10
                    No I'm sorry, cut out models/hegre if that's where the script is. The line should read:

                    $current_dir = "joyce/";

                    TGPFactory Full TGP Design & Installation Services
                    ICQ 250 142 484 · AIM TGPDynamix · Email: patrick (at) tgpfactory (dot) com
                    See who I am at AdultWhosWho.com!

                    Comment

                    Working...