formadmirer
asked on
VFP Select Image from URL
Hi all. I am trying to select the image from a url that contains both forward and back slashes. Example:
http://www.mysite.com/images\subdir\nothersubdir\image.jpg
I need to extract the image name itself into a var, in this case 'image.jpg' and the URL without the image into another, in this case 'http://www.mysite.com/images\subdir\nothersubdir\'
I have something that works great with either all forward slashes or all back slashes, but I can't get anything to work with a URL that contains random numbers of both slashes.
http://www.mysite.com/images\subdir\nothersubdir\image.jpg
I need to extract the image name itself into a var, in this case 'image.jpg' and the URL without the image into another, in this case 'http://www.mysite.com/images\subdir\nothersubdir\'
I have something that works great with either all forward slashes or all back slashes, but I can't get anything to work with a URL that contains random numbers of both slashes.
ASKER
Thanks CaptainCyril.
I did a google search for 'some image' and chose the first one to come up and ran the URL through what you provided but it didn't return either just the image name nor just the url.
Here's the url:
http://c438342.r42.cf2.rackcdn.com/wp-content/uploads/2011/01/Peter-Bjorn-and-John-Gimme-Some.jpeg
Sometimes the slashes will be mixed between forward and back, sometimes they will be only forward (like this url), and sometimes only back.
What I need is to derive just the image name, in this case 'Peter-Bjorn-and-John-Gimm e-Some.jpe g' and just the URL without the image name, in this case 'http://c438342.r42.cf2.rackcdn.com/wp-content/uploads/2011/01/'
Thanks!
I did a google search for 'some image' and chose the first one to come up and ran the URL through what you provided but it didn't return either just the image name nor just the url.
Here's the url:
http://c438342.r42.cf2.rackcdn.com/wp-content/uploads/2011/01/Peter-Bjorn-and-John-Gimme-Some.jpeg
Sometimes the slashes will be mixed between forward and back, sometimes they will be only forward (like this url), and sometimes only back.
What I need is to derive just the image name, in this case 'Peter-Bjorn-and-John-Gimm
Thanks!
That's why I used STRTRAN to change all slashes to backslashes if they are local on the PC.
You can do the reverse:
? JUSTFNAME(STRTRAN(cUrl,"\" ,"/"))
? JUSTPATH(STRTRAN(cUrl,"\", "/"))
Like this you will use the URL for internet. Do you wish to maintain the slashes?
You can do the reverse:
? JUSTFNAME(STRTRAN(cUrl,"\"
? JUSTPATH(STRTRAN(cUrl,"\",
Like this you will use the URL for internet. Do you wish to maintain the slashes?
ASKER
Oh I see now what the problem is. It's my function that's causing the issue. I'm not sure why but it's not working on this URL.
What I was using:
It was working previously, I'm not sure why it's not now.
What I was using:
lcURLImage = ALLTRIM(thisform.txtURLImage.value)
lcImageOnly = LOWER(lcURLImage)
lnRat = RAT("/", lcImageOnly)
IF (lnRat = 0)
lnRat = RAT("\", lcImageOnly)
ENDIF
IF (lnRat > 0)
lcImageOnly = SUBSTR(lcImageOnly, lnRat + 1)
ENDIF
lcURL = STRTRAN(lcURLImage, lcImageOnly, '')
It was working previously, I'm not sure why it's not now.
Change
lnRat = RAT("/", lcImageOnly)
IF (lnRat = 0)
lnRat = RAT("\", lcImageOnly)
ENDIF
to
lnRat = MAX(RAT("/",lcImageOnly),R AT("\",lcI mageOnly))
to get the maximum delimiter place no matter what type it is.
lnRat = RAT("/", lcImageOnly)
IF (lnRat = 0)
lnRat = RAT("\", lcImageOnly)
ENDIF
to
lnRat = MAX(RAT("/",lcImageOnly),R
to get the maximum delimiter place no matter what type it is.
Why aren't you using the functions that I gave you? They are shorter and more efficient.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm not sure, I must have overlooked that somehow. You are right though, much better.
Tried it, liked it, it worked - thank you!!
Tried it, liked it, it worked - thank you!!
Very much welcome!
? JUSTFNAME(STRTRAN(cUrl,"/"
? JUSTPATH(STRTRAN(cUrl,"/",