Skip to main content
Inspiring
May 19, 2008
Answered

CFHTTP - verify file first

  • May 19, 2008
  • 2 replies
  • 374 views
I am currently retrieveing files from another server via cfhttp. Occasionally, the files get renamed and my script throws an error. How can I verify if a file exists on a remote server before I make the cfhttp connection?
This topic has been closed for replies.
Correct answer Magikaru
I had to deal with the same problem about a week ago.
Here's how I got around it:

<cftry>
<cfhttp method="head" name="testTheFile" url="myurl.html"></cfhttp>
<!--- If code reaches this point, File Exists --->
<cfcatch>
<!--- File does not exist --->
</cfcatch>
</cftry>

2 replies

MagikaruCorrect answer
Inspiring
May 19, 2008
I had to deal with the same problem about a week ago.
Here's how I got around it:

<cftry>
<cfhttp method="head" name="testTheFile" url="myurl.html"></cfhttp>
<!--- If code reaches this point, File Exists --->
<cfcatch>
<!--- File does not exist --->
</cfcatch>
</cftry>
Inspiring
May 19, 2008
check the statuscode returned in the cfhttp structure: 200 means file is
there.

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/