Skip to main content
August 7, 2011
Question

Output a value from the array created by cffile uploadall

  • August 7, 2011
  • 2 replies
  • 2041 views

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?

    This topic has been closed for replies.

    2 replies

    August 8, 2011
    I tried both show_result.filesize[1] and show_result[1].filesize.  Both throw the same error message listed above.

    Inspiring
    August 8, 2011
    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

    Inspiring
    August 7, 2011

    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

    August 8, 2011

    "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.

    Inspiring
    August 8, 2011

    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