Copy link to clipboard
Copied
Okay. A case of beer up for grabs for the first person to get this one (you have to come to Johannesburg to get it though!)
I have to write an application that extracts EXIF data from photographs uploaded to the server and stores it in a database. So I try the following:
<cfimage action="read" source="#file.serverfile#" name="image" />
<cfset exif = ImageGetEXIFMetaData(image)>
<cfdump var="#exif#">
<cfquery name="yadda" datasource="#dsn">
insert into pics (focal_length) values (#focallength#) where yadda yadda fishpaste.
</cfquery>
Problem solved, right? Wrong! The dump file gives me a bunch of variables like "Exposure Time" and "Max Aperture Value". (note the spaces). I need to isolate that "exposure time" and "Max Aperture Value" variables.
<cfset focallength = ImageGetExifTag(image,"Focal Length") />
<cfoutput>#focallength#</cfoutput>
Whoo hoo!
But now, what if some malicious idiot uploads a file WITHOUT exif data? OOPS! This is where I get stuck - how do I test for the variable? How do I test if that variable exists? Easy enough to do without spaces. How do I do it WITH that space between "focal" and "length"? I've "isdefined" my way from hell to breakfast, without any luck!
PS: its late, I'm tired, and had three beers already!
Spank you in advance. Now go out and conquer!
Have a read of the docs for structKeyExists():
http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_s_27.html#137977
One of the benefits structKeyExists() has over isDefined() is that it's not hamstrung by the isDefined() function's out of date idea of what is a valid CF variable name.
One can do this:
structKeyExists(myStruct, "any string you like in here")
--
Adam
PS: I don't drink Castle, but Windhoek is OK. I know that - strictly-speaking - that's not a SAf'n beer, but it'll do 😉
Copy link to clipboard
Copied
Have a read of the docs for structKeyExists():
http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_s_27.html#137977
One of the benefits structKeyExists() has over isDefined() is that it's not hamstrung by the isDefined() function's out of date idea of what is a valid CF variable name.
One can do this:
structKeyExists(myStruct, "any string you like in here")
--
Adam
PS: I don't drink Castle, but Windhoek is OK. I know that - strictly-speaking - that's not a SAf'n beer, but it'll do 😉
Copy link to clipboard
Copied
Adam - you are obviosuly a very wise man - not only did you solve my problem, you have enough common sense not to drink Caste. I would not force SA beer on my worst enemy's dog. Your Windhoeks are waiting for you.