Copy link to clipboard
Copied
Hello. I am playing around with the cffile tag, more specifically, the cffile action="uploadall". I am having trouble getting specific values from the array that is created by the result part of the tag though. So I have the following...
<cffile action="uploadall"
destination="C:\websites\mysite\pictures\"
nameconflict="makeunique"
result="show_result">
It puts the files that were uploaded by cffileupload in the correct directory. However, I then output the result like this: <cfdump var="#show_result#"> and it gives me an array of values that I would like to use but I can't seem to output them correctly. I attached a pic so you can see part of the dump. I try to output the FILESIZE part of the array like so #show_result.filesize[1]# but I get an error.
Can someone show me the correct syntax I should use to output the FILESIZE,CLIENTFILENAME, etc?
Copy link to clipboard
Copied
You are treating show_result as a struct of arrays with the notation you are using. It's an array of structs.
When referencing an element in an array, you first need to specify which element, eg:
show_result[1]
Then if that element is a struct, you need to reference whichever key you're after:
show_result[1].filesize
What was the error message you got, btw? Did that not give you a hint as to where you were going wrong?
--
Adam
Copy link to clipboard
Copied
"You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members"
I tried both show_result.filesize[1] and show_result[1].filesize. Both throw the same error message listed above.
Copy link to clipboard
Copied
Post the relevant bits of the code, including the CFDUMP and the line at which you're getting the error.
Remove anything that is not relevant (like HTML).
--
Adam
Copy link to clipboard
Copied
I don't think you don't really need any of that... you have all the info required to help me answer this one. The image being the most important bit of info.
Perhaps the question should be as simple as "how do I output any of the values shown in the picture". It's an array inside a struct... so please help me understand how to output that to the screen.
Copy link to clipboard
Copied
Do you think I would have asked for it just for the hell of it?
I've already told you what you need to do to access the data from the array of structs that you have shown us the dump for, and that is not working. Which demonstrates to me that there's more going than you are explaining.
So, like, post the code.
--
Adam
Copy link to clipboard
Copied
Yikes.
Copy link to clipboard
Copied
Adam is right in that we need to see more of the code because the error does not match the screenshot/scenario. Because we cannot see all that is going on within this section of code we can only make logical guesses. Having said that, I would guess that you are overwriting that variable as a simple string shortly after the cfdump.
Copy link to clipboard
Copied
Having said that, I would guess that you are overwriting that variable as a simple string shortly after the cfdump.
Well: quite.
However we wouldn't need to waste everyone's time postulating about it if the code was posted when it was asked for. We could just look at the code, point out where it's wrong, explain why, get it fixed, and move on.
Getting & giving help is not rocket science, and it also really oughtn't be made into an exercise akin to pulling teeth.
--
Adam
Copy link to clipboard
Copied
<cffile action="uploadall"
destination="C:\websites\mysite\pictures\"
nameconflict="makeunique"
result="show_result">
<cfmail to="myemail" from="myemail" subject="processed file">
<cfdump var="#show_result#">
#show_result.filesize[1]#
</cfmail>
Copy link to clipboard
Copied
#show_result.filesize[1]#
I've already told you that's wrong, and explained why.
😐
What happens if you revise it thus:
<cffile action="uploadall"
destination="C:\websites\mysite\pictures\"
nameconflict="makeunique"
result="show_result"><cfmail to="myemail" from="myemail" subject="processed file">
<cfdump var="#show_result#">
#show_result[1].filesize#
</cfmail>
?
--
Adam
Copy link to clipboard
Copied
I tried both show_result.filesize[1] and show_result[1].filesize. Both throw the same error message listed above.
Copy link to clipboard
Copied
I tried both show_result.filesize[1] and show_result[1].filesize. Both throw the same error message listed above.
I don't believe you. I don't mean to suggest that you are lying, but I do believe you are mistaken. Or you are misrepresenting the situation by not actually posting the actual code you are running. The only way you could get that message is if show_result was a string, which you have demonstrated it not to be, in your CFDUMP.
Run this code:
<cffile action="uploadall"
destination="C:\websites\mysite\pictures\"
nameconflict="makeunique"
result="show_result">
<cfdump var="#show_result#">
<cfoutput>#show_result[1].filesize#</cfoutput>
This will show the dump as per before, and it will show the value of the filesize of the first uploaded file.
--
Adam