Skip to main content
Participating Frequently
December 14, 2010
Answered

Can I test to see if a remote url file exists?

  • December 14, 2010
  • 3 replies
  • 16495 views

I need to check to see if an mp3 file exists on a remote server. Can someone help me with this code?

thanks,

Richie

This topic has been closed for replies.
Correct answer ilssac

It is not going to return a yes or no.  It is going to return a structure.  YOu then examin that structure to determine if it was a yes or no.

As BKBK showed

<cfhttp method="head" url="http://www.myurl.com/mymp3.mp3">

...

<cfdump var="#cfhttp#">

You would then be looking for a "200 OK" status.  200 OK is the HTTP status that the URL was found and returned what was requested.

<cfhttp...> documentation.

http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_g-h_09.html

3 replies

Participant
December 19, 2010

hehehe

Owainnorth
Inspiring
December 19, 2010

Well, good and thorough work from many people there, from which I think we can conclude:

  "Don't use functions for things they weren't intended"

Personally I'd be sticking to the cfhttp suggested in the first post. Couldn't agree more with Adam though, that the inappropriately named "livedocs" should possibly be renamed as Adobe MoribundDocs. Very frustrating not having up-to-date documentation when it's needed.

BKBK
Community Expert
Community Expert
December 19, 2010

Owainnorth wrote:

Well, good and thorough work from many people there, from which I think we can conclude:

  "Don't use functions for things they weren't intended"

Personally I'd be sticking to the cfhttp suggested in the first post.

I should add a reminder here that I was merely making an experimental suggestion to test ColdFusion's capability. It's achieved one result: we've narrowed it down to CF9.0.1!

Using cfhttp is naturally the most appropriate way to do it presently. However, it would be neat to officially have fileExists(arg:URL) in CF9.0.1 onwards.

BKBK
Community Expert
Community Expert
December 14, 2010

<!--- Head method is same as Get method, but here, server doesn't send back any response. We only need to check whether file exists --->
<cfhttp method="head" url="url_of_the_mp3_file">

BKBK
Community Expert
Community Expert
December 14, 2010

I reacted before seeing the last post.

ilssac
Inspiring
December 14, 2010

<cfhttp....> to the url of the MP3 on the server.  Using the head option if you don't want to download the actual MP3 file.

A status 200 ok in the returned structer of the <cfhttp...> call would indicate that it exists, or at least something exists, at that url.

You may want to investigate other information in the returned structure to confirm that it is the specific desired content.

Participating Frequently
December 14, 2010

Say the url is http://www.myurl.com/mymp3.mp3

How would I get <cfhttp to return a yes or a no?

ilssac
ilssacCorrect answer
Inspiring
December 14, 2010

It is not going to return a yes or no.  It is going to return a structure.  YOu then examin that structure to determine if it was a yes or no.

As BKBK showed

<cfhttp method="head" url="http://www.myurl.com/mymp3.mp3">

...

<cfdump var="#cfhttp#">

You would then be looking for a "200 OK" status.  200 OK is the HTTP status that the URL was found and returned what was requested.

<cfhttp...> documentation.

http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_g-h_09.html