[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 864
  • Last Modified:

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.
0
formadmirer
Asked:
formadmirer
  • 6
  • 3
1 Solution
 
CaptainCyrilCommented:
cURL = "http://www.mysite.com/images\subdir\nothersubdir\image.jpg"

? JUSTFNAME(STRTRAN(cUrl,"/","\"))
? JUSTPATH(STRTRAN(cUrl,"/","\"))
0
 
formadmirerAuthor Commented:
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!
0
 
CaptainCyrilCommented:
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
formadmirerAuthor Commented:
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.
0
 
CaptainCyrilCommented:
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.
0
 
CaptainCyrilCommented:
Why aren't you using the functions that I gave you? They are shorter and more efficient.
0
 
CaptainCyrilCommented:
lcImageOnly = JUSTFNAME(lcURLImage)
lcURL = STRTRAN(lcURLImage, lcImageOnly, '')
0
 
formadmirerAuthor Commented:
I'm not sure, I must have overlooked that somehow. You are right though, much better.
Tried it, liked it, it worked - thank you!!
0
 
CaptainCyrilCommented:
Very much welcome!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now