Reading Folders

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DaRemedy

    Reading Folders

    Hiya,

    If I had several folders full of images, how can I get PHP to open the
    folder, read the image names and save the image names (inc extension) to a
    MySQL database?

    What I am trying to do is create an image gallery using PHP/MySQL, so that
    everytime i take a load of pics, all I would have to do is get PHP to read
    the contents of the folder and add the filenames to a MySQL database rather
    than having to manually input the names into the database

    Any help would be great.

    Cheers.

    DaRemedy


  • Andy Hassall

    #2
    Re: Reading Folders

    On Mon, 8 Nov 2004 19:32:10 +0000 (UTC), "DaRemedy"
    <demonnet@btint ernet.com.nospa m> wrote:
    [color=blue]
    >If I had several folders full of images, how can I get PHP to open the
    >folder, read the image names and save the image names (inc extension) to a
    >MySQL database?
    >
    >What I am trying to do is create an image gallery using PHP/MySQL, so that
    >everytime i take a load of pics, all I would have to do is get PHP to read
    >the contents of the folder and add the filenames to a MySQL database rather
    >than having to manually input the names into the database[/color]

    opendir, loop of readdir + mysql_query, closedir.

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Chris Hope

      #3
      Re: Reading Folders

      DaRemedy wrote:
      [color=blue]
      > If I had several folders full of images, how can I get PHP to open the
      > folder, read the image names and save the image names (inc extension) to a
      > MySQL database?
      >
      > What I am trying to do is create an image gallery using PHP/MySQL, so that
      > everytime i take a load of pics, all I would have to do is get PHP to read
      > the contents of the folder and add the filenames to a MySQL database
      > rather than having to manually input the names into the database[/color]

      http://www.php.net/opendir & http://www.php.net/readdir

      --
      Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

      Comment

      • Matt Bradley

        #4
        Re: Reading Folders

        DaRemedy wrote:[color=blue]
        > Hiya,
        >
        > If I had several folders full of images, how can I get PHP to open the
        > folder, read the image names and save the image names (inc extension) to a
        > MySQL database?
        >
        > What I am trying to do is create an image gallery using PHP/MySQL, so that
        > everytime i take a load of pics, all I would have to do is get PHP to read
        > the contents of the folder and add the filenames to a MySQL database rather
        > than having to manually input the names into the database[/color]

        One thing you should remember if the filenames col of your MySQL is
        going to be unique:

        The Linux filesystem is case-sensitive, so FILENAME.gif FileName.gif,
        and and filename.gif can all exist in the same directory at once. MySQL
        text fields however aren't case sensitive in the same way, so you
        couldn't have all three stored in the same unique field in separate rows.


        --
        Matt Bradley
        Put smarties tubes on cats legs make them walk like robots.

        Comment

        • Harrie Verveer

          #5
          Re: Reading Folders

          the previous replies say it all.. however it might be nice to
          automatically create thumbnails as well with GDlib, while you're looping
          through the files:

          http://nl3.php.net/manual/en/functio...yresampled.php (nice)
          or
          http://nl3.php.net/manual/en/functio...opyresized.php (crappy)

          DaRemedy wrote:[color=blue]
          > Hiya,
          >
          > If I had several folders full of images, how can I get PHP to open the
          > folder, read the image names and save the image names (inc extension) to a
          > MySQL database?
          >
          > What I am trying to do is create an image gallery using PHP/MySQL, so that
          > everytime i take a load of pics, all I would have to do is get PHP to read
          > the contents of the folder and add the filenames to a MySQL database rather
          > than having to manually input the names into the database
          >
          > Any help would be great.
          >
          > Cheers.
          >
          > DaRemedy
          >
          >[/color]

          Comment

          • DaRemedy

            #6
            Re: Reading Folders

            Wow,

            Thanks guys, I really appreciate all your help.

            Even though I am a total newb, I will read up and try out the suggestions
            posted. What I am trying to do is create an online image gallery like the
            one used on the Bungie site located at

            On the site, they have a list of categories such as renders, concept art
            etc, which displays each image thumbnails when clicked upon. These
            thumbnails are linked to a popup window displaying the larger image. I know
            that this is a simple image gallery, but I don't even know where to begin :(

            Thanks once again, guys.

            DaRemedy.


            "Harrie Verveer" <newsgroup{remo ve-this}@harriever veer.com> wrote in message
            news:kISdnSu4D7 CQDw3cRVnyiQ@ze elandnet.nl...[color=blue]
            > the previous replies say it all.. however it might be nice to
            > automatically create thumbnails as well with GDlib, while you're looping
            > through the files:
            >
            > http://nl3.php.net/manual/en/functio...yresampled.php (nice)
            > or
            > http://nl3.php.net/manual/en/functio...opyresized.php (crappy)
            >
            > DaRemedy wrote:[color=green]
            >> Hiya,
            >>
            >> If I had several folders full of images, how can I get PHP to open the
            >> folder, read the image names and save the image names (inc extension) to
            >> a
            >> MySQL database?
            >>
            >> What I am trying to do is create an image gallery using PHP/MySQL, so
            >> that
            >> everytime i take a load of pics, all I would have to do is get PHP to
            >> read
            >> the contents of the folder and add the filenames to a MySQL database
            >> rather
            >> than having to manually input the names into the database
            >>
            >> Any help would be great.
            >>
            >> Cheers.
            >>
            >> DaRemedy
            >>[/color][/color]

            Comment

            • Harrie Verveer

              #7
              Re: Reading Folders

              Take it step by step. First try to just list the image names in a dir
              with an echo(). Then, try putting those filenames in the database. After
              that, try creating one thumbnail with imagecopyresamp led or
              imagecopyresize d - then add it in your loop. Make something that reads
              your database table. First, just let the script display the fetched
              filenames. Then add an <IMG> tag around it, etc. etc. Don't build the
              entire application at once - especially when you just started in PHP (or
              any other programming langage), just take it step-by-step.

              DaRemedy wrote:[color=blue]
              > I know
              > that this is a simple image gallery, but I don't even know where to begin :([/color]

              Comment

              • Harrie Verveer

                #8
                Re: Reading Folders

                that's correct - a solution might be adding the filenames encrypted into
                the database?
                [color=blue]
                > The Linux filesystem is case-sensitive, so FILENAME.gif FileName.gif,
                > and and filename.gif can all exist in the same directory at once. MySQL
                > text fields however aren't case sensitive in the same way, so you
                > couldn't have all three stored in the same unique field in separate rows.[/color]

                Comment

                • DaRemedy

                  #9
                  Re: Reading Folders

                  Thankyou very much, Harrie

                  Your help and advice are greatly appreciated, my friend.

                  I will try building the application in step-by-step stages and will let you
                  know how it goes.

                  Take Care.

                  DaRemedy.

                  "Harrie Verveer" <newsgroup{remo ve-this}@harriever veer.com> wrote in message
                  news:TJ6dnTw08v E0MQ3cRVnyrw@ze elandnet.nl...[color=blue]
                  > Take it step by step. First try to just list the image names in a dir with
                  > an echo(). Then, try putting those filenames in the database. After that,
                  > try creating one thumbnail with imagecopyresamp led or imagecopyresize d -
                  > then add it in your loop. Make something that reads your database table.
                  > First, just let the script display the fetched filenames. Then add an
                  > <IMG> tag around it, etc. etc. Don't build the entire application at
                  > once - especially when you just started in PHP (or any other programming
                  > langage), just take it step-by-step.
                  >
                  > DaRemedy wrote:[color=green]
                  >> I know that this is a simple image gallery, but I don't even know where
                  >> to begin :([/color][/color]


                  Comment

                  • Geoff Berrow

                    #10
                    Re: Reading Folders

                    I noticed that Message-ID:
                    <4190cd36$0$632 6$cc9e4d1f@news .dial.pipex.com > from DaRemedy contained
                    the following:
                    [color=blue]
                    >
                    >I will try building the application in step-by-step stages and will let you
                    >know how it goes.[/color]

                    Try this to get you going. You can see the result at


                    <html>
                    <body>

                    <?php
                    //insert relative path to directory below
                    $path="../path/to/directory/";
                    if ($handle = opendir($path)) {
                    while (false !== ($file = readdir($handle ))) {
                    if(strpos($file ,"jpg")!=fal se)
                    {
                    echo "<span style=\"float: left;padding: 5;margin-bottom
                    5;\"><img src=\"$path$fil e\"></span>\n";}
                    }

                    }
                    ?>
                    </body></html>

                    --
                    Geoff Berrow (put thecat out to email)
                    It's only Usenet, no one dies.
                    My opinions, not the committee's, mine.
                    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                    Comment

                    • Andy Hassall

                      #11
                      Re: Reading Folders

                      On Tue, 09 Nov 2004 14:07:08 +0100, Harrie Verveer
                      <newsgroup{remo ve-this}@harriever veer.com> wrote:
                      [color=blue][color=green]
                      >> The Linux filesystem is case-sensitive, so FILENAME.gif FileName.gif,
                      >> and and filename.gif can all exist in the same directory at once. MySQL
                      >> text fields however aren't case sensitive in the same way, so you
                      >> couldn't have all three stored in the same unique field in separate rows.[/color]
                      >
                      >that's correct - a solution might be adding the filenames encrypted into
                      >the database?[/color]

                      Don't trash the data, fix the database. MySQL has perfectly good
                      case-sensitive types.



                      --
                      Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
                      <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

                      Comment

                      • method
                        New Member
                        • Feb 2006
                        • 6

                        #12
                        Hi guys. could any one tell me how i can reead sub directory content using php and then write it to mysql database ? I be happy if an expert show me how .Thanks

                        Comment

                        Working...