#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    23
    Rep Power
    0
    Greetings, all. I have a directory with images, of which I need to place the file names in a column in a MySQL db. There are two files for every image:
    image.jpg and image_t.jpg (the thumbnail for image.jpg)

    What I would like to do is strip the file extension (as well as the '_t.jpg') from the filenames, and just enter the 'root' filename (image). This way I have only one db entry per image pair.

    Can anyone help me with this?
    Thanks!!
    Dale.

    [This message has been edited by rainmaker (edited July 03, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Aalborg, Denmark
    Posts
    36
    Rep Power
    15
    Hi

    First you get the filenames in the directory:
    $myDir = opendir("path/to/images/");

    then you do something like:
    $lastImage = "";

    while($entry = readdir($myDir)) {
    if($entry != "." && $entry != "..") {
    $entry = ereg_replace("_t.jpg", "", $entry);
    $entry = ereg_replace(".jpg", "", $entry);
    if($entry != $lastImage) {
    <store $entry in db>
    }
    $lastImage = $entry;
    }
    }

    NOTICE: this is not bug-checked, tested or validated in any way. It is furthermore not the most elegant way to solve the problem, but it will get the job done

    When you store the imagename you should also make a check, that it doesn't exist allready. Perhaps even make the name unique.

    Hope this will help you.

    Regards

    // Martin

Similar Threads

  1. Replies: 1
    Last Post: February 6th, 2004, 09:09 PM
  2. Backing up directory
    By purplegrum in forum Linux Help
    Replies: 5
    Last Post: December 18th, 2003, 04:57 AM
  3. List all images filenames from directory into listbox ?
    By stojan in forum PHP Development
    Replies: 3
    Last Post: November 5th, 2003, 12:45 PM
  4. Display filenames that start with XXX... in a directory
    By kimy_cool in forum PHP Development
    Replies: 2
    Last Post: October 6th, 2003, 01:16 PM
  5. Can't copy the next chunk of files into new directory?
    By Diyar in forum Perl Programming
    Replies: 1
    Last Post: September 22nd, 2003, 01:52 AM

IMN logo majestic logo threadwatch logo seochat tools logo