Skip to main content
Participating Frequently
December 14, 2010
해결됨

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

  • December 14, 2010
  • 3 답변들
  • 16495 조회

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

thanks,

Richie

이 주제는 답변이 닫혔습니다.
최고의 답변: 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 답변

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.

RichieWhite작성자
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?

BKBK
Community Expert
Community Expert
December 16, 2010

Perhaps this is a 9.0.1 thing - I tested with 9.0.0 as I haven't upgraded this machine yet.

Dave Watts, CTO, Fig Leaf Software

http://www.figleaf.com/

http://training.figleaf.com/

Read this before you post:

http://forums.adobe.com/thread/607238


Dave Watts wrote:

Perhaps this is a 9.0.1 thing - I tested with 9.0.0 as I haven't upgraded this machine yet.

Indeed. I am on build 9.0.1.274703