3

So I'm new to coding in coldfusion, this being my second month, so bear with me on this.

My employer's client wants to upload multiple files handling errors smoothly, meaning that it will continue on through all the uploads even if there was an error.

So with CF11, I can use uploadAll with the optional values of continueOnError and Errors enabled to handle the multiple files easily.

Problem is, is that my employer's testing server is still only CF10, and might not get updated anytime soon. So continueOnError and Error will fail on compile on our testing server, but not on the clients server.

I would like to be able to do something like:

<cfif SERVER.ColdFusion.ProductVersion gte 11>
    <optimal cffile uploadAll code>
<cfelse>
    <suboptimal cffile uploadAll code>
</cfif>

And not have any problems with compiling. But the testing server has a problem with the code anyway. Is there any way that this can be done within the code? If not, is there a way that I can do this fairly easily...ish?

Jim
  • 85
  • 3
  • 3
    It would be best if you tested the code on the same version of the server on which it will live. With a CF license, you can use it for production and test servers without requiring a second license. – Scott Stroz Jul 11 '14 at 20:41
  • 2
    There is no point having a testing server that is not the same version as the live server. Don't fix your code, fix your environment. There is no reason not to (even though you say "and might not get updated anytime soon"). That said, Henry has given you the same answer I would if it was completely a code-centric one. Seriously though: get your environments sorted out. – Adam Cameron Jul 11 '14 at 21:43
  • ScottStroz & Adam Cameron, I agree with you guys that you having a test server that has a lower version than the live version is problematic, but as to why, that is out of my hands. I've informed my boss and he'll talk with his boss on whether they want to spend $4000 on the upgrade, but I have to work with/around what I got available. Plus my question might help out others with a similar problem, seeing I found no other sources. – Jim Jul 12 '14 at 19:18
  • It could be worse. You could have your dev server on the higher version. – Dan Bracuk Jul 13 '14 at 11:50

1 Answers1

8

Use <cfinclude>.

<cfif SERVER.ColdFusion.ProductVersion gte 11>
    <cfinclude template="newWay.cfm">
<cfelse>
    <cfinclude template="oldWay.cfm">
</cfif>

This is how cfbackport does it: https://github.com/misterdai/cfbackport/blob/master/cfbackport.cfm

Henry
  • 32,689
  • 19
  • 120
  • 221
  • This worked with what I was trying to do. At first, I was worried that I couldn't return data back from the cfm files, seeing that uploadAll (CF11) stores data for both the errors and successes, and that I saw no information on what cfinclude returns. But I found out that a variable stays within scope. *variable gets best data* *variable gets data* Not 100% sure why the compiler compiles one file over the other, but I'll look more into that when I have a spare minute or two. Thanks for your answer. – Jim Jul 12 '14 at 19:35
  • One limitation of this approach is the source-less deployment via cfcompile. The old way may be compiled with warning or errors such as function name collision. – Henry Nov 20 '14 at 19:34