Lunarpages Web Hosting Forum

Author Topic: Wildcards in src directory for image loading - this possible  (Read 1829 times)

Offline RolandGS

  • Spacescooter Operator
  • *****
  • Posts: 30
    • http://www.SarJent.com
Wildcards in src directory for image loading - this possible
« on: January 28, 2005, 06:36:16 AM »
Hoping to save some time here.  My client has a large amount of image data that is to be displayed on our site.  It is currently in a directory structure that is "Almost" condusive for use in code.  For each page I will be loading up images related to an ID number.  Such as:

ID:        10000
Item:     Item10000
images: Item10000-A.JPG
             Item10000-B.JPG
             Item10000-C.JPG

The ID is retrieved from a mySQL query along with the description and other data items that are displayed on the page.

The problem is with the directory structure that this data is in.  This structure is like this:

images/equipment/Item10000 a description/Item10000-A.JPG
images/equipment/Item10000 a description/Item10000-B.JPG
images/equipment/Item10000 a description/Item10000-C.JPG
images/equipment/Item10001 a different description/Item10001-A.JPG
images/equipment/Item10001 a different  description/Item10001-B.JPG

The problem is that the part of the Item##### sub directory that is a junk discription is not in data.  i.e. there is not way to pre-format it as a string.  However the begining part of the directory will always be Item#####.

What I was wondering is... Is there a way to provide a wildcard character into the src reference of an image... something like:

<img src ="images/equipment/Item10001~/Item10001-B.JPG">  So that I can still load from this directory but not have to worry about this random text that I can not recreate?

The alternative of course is to just redo the directory structure - removing the descriptions.  However due to the amount of my clients images data I would like to program a way around this.  I can write a script easily enough to strip out these descriptions but my client uses this structure internally for other reasons and it would make future uploads to the website easier if the internal and website structures where the same.

Thank in advance.
RolandGS

Offline Nibbler

  • 21st century digital boy
  • Master Jedi
  • *****
  • Posts: 1168
    • Coppermine
Wildcards in src directory for image loading - this possible
« Reply #1 on: January 28, 2005, 06:51:52 AM »
You can't use wildcards like that, the browser needs specific filenames to request from your server. The best option would be to generate the links automatically from the file structure using a server side script like php.
Missing since 1983


Offline RolandGS

  • Spacescooter Operator
  • *****
  • Posts: 30
    • http://www.SarJent.com
Wildcards in src directory for image loading - this possible
« Reply #2 on: January 28, 2005, 08:02:05 AM »
Here is my solution to this problem if anyone else runs into a situation like this:

As I could produce the first 9 characters of the directory name and I could also produce the parent directory from data I just loaded up a folderobject and interated thru the subfolders until I found a macth on the first 9 chars.  I then returned the full directory name.  Code follows:

<img width="100" height="100" src="images/Equipment/<%=Request.QueryString("Type")%>/<%=getFullRAPImageDir(rs("RAP_NO"), Request.QueryString("Type"))%>/<%=rs("RAP_NO")%>-A.JPG" onerror="this.src='images/default.jpg';">

function getFullRAPImageDir(RAPNumber, RAPType)
  Dim filesys
  Set filesys = CreateObject("Scripting.FileSystemObject")
  Set demofolder = filesys.GetFolder(Server.MapPath(".") & "/images/equipment/" & RAPType)
  Set folcoll = demofolder.SubFolders
    getFullRapImageDir = ""
  For Each subfol in folcoll
    if mid(subfol.Name, 1, 9) = "RAP-" & RAPNumber then
      getFullRapImageDir = subfol.Name
    end if
  Next
end function

Offline GarveysIT

  • Web Design SEO England UK
  • Berserker Poster
  • *****
  • Posts: 11648
  • Web Design SEO England UK
    • Web Design | SEO | IT Support Stockton-on-Tees, Middlesbrough, Darlington, Durham
Wildcards in src directory for image loading - this possible
« Reply #3 on: January 28, 2005, 08:03:50 AM »
RolandGS, thanks for posting the fix for us :thumb: