Link to home
Start Free TrialLog in
Avatar of formadmirer
formadmirerFlag for United States of America

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.
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

cURL = "http://www.mysite.com/images\subdir\nothersubdir\image.jpg"

? JUSTFNAME(STRTRAN(cUrl,"/","\"))
? JUSTPATH(STRTRAN(cUrl,"/","\"))
Avatar of formadmirer

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-Gimme-Some.jpeg' and just the URL without the image name, in this case 'http://c438342.r42.cf2.rackcdn.com/wp-content/uploads/2011/01/'

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?
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:
	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, '')

Open in new window


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),RAT("\",lcImageOnly))

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
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm not sure, I must have overlooked that somehow. You are right though, much better.
Tried it, liked it, it worked - thank you!!
Very much welcome!