I am dealing with an online telephone directory. I will have a folder that contains hundreds of advertising images. Each IMAGE name will have a 6 digit number (somewhere within the file name) that corresponds to the ad_name field in my main database. These image files will be either JPG, GIF, or PNG (but will all have the same extension)

In my listing data, any listing that contains a display ad (an image) will have an "ad_name > 0"

For example if Joe's Auto purchased a display ad, his listing data would contain a number like 112534 in the ad_name field. That is a system generated ad name.

When we create the IMAGE, we MUST include that series of numbers somewhere in the file name. So we would create an image file named something like this:
joes_auto_112534.jpg, or 112534_joes_auto.gif.

What i need to figure out is... if I run acrosss a listing that has an ad_name greater than zero - that customers purchased an ad, and a file exists on the server that has the ad_name entry somewhere in the file name - how do I find THAT file and return ONLY the file name - not the path?

    I would store the file name with the ad in the db.

      I looked at that option and that would be a really simply thing to implement but I dont want to rely on the ad designer filling that in (one more step for them to remember) .

      What I CAN rely on is the system generated ad_name (e.g.: 142323) I know that this number WILL match a file name somewhere, because if they dont, the ad will not show up in the printed telephone directory and if the ads are not in the printed directory - we have big problems ;-)

      The best way to accomplish this is to be able to search for the ad_name within the file name and return the file name. I've seen various examples, but am having trouble grasping some of the concepts and can't successfully implement them.

      I appreciate your response!

        glob(), but this still sub optimal, you should be able to automate the adding the file name to the db

          You'd do that the exact same way as you create the filename. 'joe_auto_ comes from somewhere, and you append 1234 to it. If you can do that for a file, you can do it to a db entry.

            The data I get for my website is exported from a proprietary directory publishing system. We sell an ad to Customer X. We create an entry in our publishing system, it generates a six digit ad_name. We then exit our publishing, move over to InDesign, manually create an image file, and manually give it a name that MUST include the six digit number. Because when we run pagination for our printed directory, the publishing system LOOKS for that number within the ad image file name.

            Having several designers, we need to allow them the flexibility to name a file what ever they like - so long as it includes the six digit number.

            To bring the data and images into my PHP/mysql website I have two steps. First I export the data out of our publishing system. Then I take a copy of all the images from the InDesign folder and move them over to the web server. The only thing that RELATES the images to a record from the publishing system is that six digit number. Other than that they are completely separate.

            So the idea of putting the file name in the DB - In order to automate that process I would still need the ability to search a file name for the six digit number. And in my big picture, the most flexible option, is to have the website go get the record for customer x, get the six digit number, and then go find the name of the file that contains those six digits.

            Hopefully that makes sense and I haven't talked in circles or muddied the water MORE ;-)

            Thanks again all of you for your input. !

              I'd rather do the work once and then use finished results when serving contents. That is, stick with inserting the actual filename in the DB.
              Move the files you need to process for db insertion into a specific directory, say some/path/import.
              Then, go through all those files, parse out the number from each filename, and when you insert the data in the db, you have both your number and your filename. And suddenly you have the filename to relate the records with files without mucking about in muddy regexp waters.

                Write a Reply...